views:

185

answers:

1

Hi,

I need some help with this problem, please. For days I have been trying now.

The retrieving off feeds and parsing them is not really a problem, but Uploading data in the form off xml is?

The code below is partially from the google docs samplecode also, but obviously it's not working.

I hope someone else is more into the google api workings, because I have no idea. Currently, I am only attempting to add a tag to a photo in an album. Once that works, I can probably do the rest also.

public function postTag() { 
    $query='smarty'; 
    $this->updateOptie('tag', $query); 
    $feedUrl = $this->creeerFeedUrl('myalbum', false); 
    $picasa = $this->parseFeed( $feedUrl ); 
    $gphoto = $picasa['gphoto'][0];    
    $gphotoid = $gphoto['id']; 

    //return $gphotoid; 
    ////////////////////sofar no problem//////////////////  



     $tag = "mytag"; 
       $data = "<entry xmlns='http://www.w3.org/2005/Atom'&gt;
    <title>$tag</title>
    <category scheme=\"http://schemas.google.com/g/2005#kind\" term=\"http://schemas.google.com/photos/2007#tag\"/&gt; 
</entry>";    
    $albumid = 'myalbum'; 
    $itemsFeedURL = $this->krijgPicasaBasisUrl(). "/albumid/$albumid/photoid/$gphotoid"; 
    $len=strlen($data); 

    $headers = array( 
        "Authorization: GoogleLogin auth=" . $this->auth, 
        "GData-Version: 2", 
        'Content-Type: application/atom+xml', 
        "Content-Length: $len", 
        ); 

      $ch = curl_init();    /* Create a CURL handle. */ 


      /* Set cURL options. */ 
      curl_setopt($ch, CURLOPT_URL, $itemsFeedURL); 
      curl_setopt($ch, CURLOPT_POST, true); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
      curl_setopt($ch, CURLOPT_FAILONERROR, true); 
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers ); 
      curl_setopt($ch, CURLOPT_POSTFIELDS,$data); 
     $result = curl_exec($ch);  /* Execute the HTTP request. */
       $info = curl_getinfo($ch);
      curl_close($ch);           /* Close the cURL handle. */
     return $info;

thanks, rich

+1  A: 
  1. Your quoting is broken. The code as you posted in your quesion can't work, because $data contains unescaped double quotes ". You need to escape them all like so: \". If this is that way in the code, that may already be the problem.

  2. Use echo curl_error() after the curl_exec() call to see whether something went wrong during the upload.

Pekka
Well, curl can act differently on your own server depending on settings. And the quoting was probably not that way on the picasa site, was it? Can you post a link?
Pekka
Thanks, my fault. This was just on SO. I copypasted it again right out off the picasa light class?
Richard
All right, then it's `curl_error()` time.
Pekka
I don't know much about curl settings on the server and the way that it can affect certain requests? I wil look up the link for picasalight. It's the only one out there I could find, that is not related to zend.
Richard
ah, here it is http://www.cameronhinkle.com/blog/id/5079549798227445041
Richard
Just add `echo curl_error(); ` right in between the curl_exec() and the curl_info() lines. What happens? Do any error messages come up? What happens anyway, do you get any error messages?
Pekka
yes, I get an error 404, that makes no sense to me?
Richard
Well, what's the value of `$itemsFeedURL`? Put in a `echo $itemsFeedURL;`
Pekka
Try opening the URL you specified in your browser. It returns `Invalid entity id: tsa_ch`. That's probably your problem - sounds like an invalid albbum or something. Also, when I open the base URL http://picasaweb.google.com/data/feed/api/user/rich3607/, I don't see any albums there. I think you can sort this out now, I'm off for tonight. `Night!
Pekka
thanks for your help, I think thats probably due to the fact that I set the album to private? maybe that is something I should investigate?
Richard
Yes! Try setting it to public, it'll probably work.
Pekka
thanks for your help,I have some testing to do. Night then
Richard
I finally found the problemIt was in the itemsfeedUrl--there is a difference in using--/albumid/$albumid--and----/album/$albumid--because with the latter you can identify the album with it's name.
Richard
Ah! Good to know. Nice that it worked out.
Pekka