开发者

php upload xml to google api

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////////////开发者_如何学JAVA//////  



     $tag = "mytag"; 
       $data = "<entry xmlns='http://www.w3.org/2005/Atom'>
    <title>$tag</title>
    <category scheme=\"http://schemas.google.com/g/2005#kind\" term=\"http://schemas.google.com/photos/2007#tag\"/> 
</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. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜