Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 2.01 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Is it possible to use a batch request to create documents and add acl to them in the same request?
  2. <?php
  3. public function batch($content) {
  4.     return '<feed xmlns="http://www.w3.org/2005/Atom"
  5.         xmlns:docs="http://schemas.google.com/docs/2007"
  6.         xmlns:batch="http://schemas.google.com/gdata/batch"
  7.         xmlns:gd="http://schemas.google.com/g/2005">' . $content . '</feed>';
  8. }
  9. public function batchCopyAndShare($title, $emails, $role = 'writer', $scope = 'user') {
  10.     $url = 'https://docs.google.com/feeds/default/private/full/batch';
  11.     $entries = '';
  12.     $id = 1;
  13.     foreach($emails as $email) {
  14.         $entries .= '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gAcl="http://schemas.google.com/acl/2007">' .
  15.             "<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/acl/2007#accessRule'/>" .
  16.                 '<id>https://docs.google.com/feeds/default/private/full/spreadsheet%3A' . $this->id() . '</id>
  17.                 <title>' . $title . ' - ' . $email . '</title>'
  18.             . "<gAcl:role value='$role'/>"
  19.             . "<gAcl:scope type='$scope' value='$email'/>"
  20.         . "</entry>";
  21.     }
  22.     $entry = '<?xml version="1.0" encoding="UTF-8"?>' . $this->batch($entries);
  23.     $res = (gget('POST', $url, array(), $entry));
  24.     return $res;
  25. }
  26. ?>
  27.        
  28. <?php
  29. batchCopyAndShare("title", array("email@address.com"));
  30. ?>
  31.        
  32. <feed xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005">
  33.     <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gAcl="http://schemas.google.com/acl/2007">
  34.         <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/acl/2007#accessRule'/>
  35.         <id>https://docs.google.com/feeds/default/private/full/spreadsheet%3Adocumentid</id>
  36.         <title>title - email@address.com</title>
  37.         <gAcl:role value='writer'/>
  38.         <gAcl:scope type='user' value='email@address.com'/>
  39.     </entry>
  40. </feed>