【发布时间】:2014-05-13 14:31:45
【问题描述】:
我正在使用来自 https://developers.google.com/google-apps/spreadsheets/ 的 Google 自己的示例
他们说:
要更新现有行的内容,首先检索要更新的行,根据需要对其进行修改,然后将消息正文中包含更新行的 PUT 请求发送到行的编辑 URL。
确保您 PUT 条目中的 id 值与现有条目的 id 完全匹配。编辑 URL 在以下行条目中突出显示:
<entry gd:etag='"S0wCTlpIIip7ImA0X0QI"'>
<id>https://spreadsheets.google.com/feeds/list/key/worksheetId/private/full/rowId</id>
<updated>2006-11-17T18:23:45.173Z</updated>
<category scheme="http://schemas.google.com/spreadsheets/2006"
term="http://schemas.google.com/spreadsheets/2006#list"/>
<title type="text">Bingley</title>
<content type="text">Hours: 10, Items: 2, IPM: 0.0033</content>
<link rel="self" type="application/atom+xml"
href="https://spreadsheets.google.com/feeds/list/key/worksheetId/private/full/rowId"/>
<link rel="edit" type="application/atom+xml"
href="https://spreadsheets.google.com/feeds/list/key/worksheetId/private/full/rowId/version"/>
<gsx:name>Bingley</gsx:name>
<gsx:hours>20</gsx:hours>
<gsx:items>4</gsx:items>
<gsx:ipm>0.0033</gsx:ipm>
</entry>
我一直在尝试使用以下 CURL 发送此信息(使用我自己的数据,但结构完全相同):
$headers = array(
"Authorization: GoogleLogin auth=" . $google_auth,
"GData-Version: 3.0",
"Content-Type: application/atom+xml",
"If-Match: *",
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://spreadsheets.google.com/feeds/list/$feed/0/private/full/$row_id");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$response = curl_exec($curl);
echo $response;
似乎 XML 格式不正确,这很奇怪,因为它来自 Google 的示例,当我从自己的电子表格中检索列表提要时,我得到了相同的响应。我该如何更正,还有其他问题吗?
当我将此 xml 粘贴到 http://www.freeformatter.com/xml-formatter.html 时,我收到一个错误,
Unable to parse any XML input. org.jdom2.input.JDOMParseException: Error on line 1: The prefix "gd" for attribute "gd:etag" associated with an element type "entry" is not bound.
谢谢。
【问题讨论】:
标签: php curl google-api google-spreadsheet-api