【问题标题】:php upload xml to google apiphp上传xml到google api
【发布时间】:2010-01-19 11:14:15
【问题描述】:

我需要一些帮助来解决这个问题,拜托。 这几天我一直在尝试。

检索提要并解析它们并不是真正的问题,但是 以关闭xml的形式上传数据是什么?

下面的代码也部分来自谷歌文档示例代码,但显然它不起作用。

我希望其他人更深入地研究 google api 工作,因为我不知道。 目前,我只是尝试为相册中的照片添加标签。 一旦成功了,我可能也可以完成其余的工作。

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'>
    <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;

谢谢,有钱

【问题讨论】:

  • 您在分配 $data 的地方引用错误 - 只是在 SO 上还是在您的源代码中?

标签: php xml upload curl google-api


【解决方案1】:
  1. 您的报价已损坏。您在问题中发布的代码不起作用,因为 $data 包含未转义的双引号 "。你需要像这样逃避它们:\"。如果代码中是这样,那可能已经是问题所在了。

  2. 在 curl_exec() 调用之后使用 echo curl_error() 来查看上传期间是否出现问题。

【讨论】:

  • 嗯,curl 可以根据设置在您自己的服务器上执行不同的操作。 picasa 网站上的引用可能不是这样的,是吗?能发个链接吗?
  • 谢谢,我的错。这只是在SO上。我从 picasa light 类中再次复制粘贴了吗?
  • 我不太了解服务器上的 curl 设置以及它可能影响某些请求的方式?我将查找 picasalight 的链接。这是我能找到的唯一一个,与 zend 无关。
  • 只需在 curl_exec() 和 curl_info() 行之间添加 echo curl_error(); 即可。发生什么了?是否出现任何错误消息?无论如何会发生什么,您是否收到任何错误消息?
  • 尝试打开您在浏览器中指定的 URL。它返回Invalid entity id: tsa_ch。这可能是您的问题 - 听起来像是无效的专辑之类的。此外,当我打开基本 URL picasaweb.google.com/data/feed/api/user/rich3607 时,我看不到任何专辑。我想你现在可以解决这个问题了,我今晚要走了。 `晚上!
猜你喜欢
  • 2018-11-11
  • 1970-01-01
  • 1970-01-01
  • 2015-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
相关资源
最近更新 更多