使用php curl在谷歌电子表格中写入数据?

时间:2017-06-13 05:39:49

标签: php curl google-sheets

我在使用Google电子表格时遇到了一些问题。

我已经创建了用于在我的应用程序中编写数据的类,但它不起作用,我还创建了用于获取电子表格的类以及它的完美工作。

我使用curl而不是php电子表格库来尝试代码。

这是我的代码

public function writeSheet($xml){

$headers = array(
"Authorization: Bearer {$this->AccessToken}",
"GData-Version: 3.0",
"Content-Type: application/atom+xml"
);

$curl = curl_init();

$ URL1 = “https://spreadsheets.google.com/feeds/list/*****spreadsheetid*******/1/private/full”;

curl_setopt($curl, CURLOPT_URL, $url1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
$info = curl_getinfo($curl);

echo "<pre>";
print_r($response);
exit();

}

在其他文件上我调用函数来编写,这里是代码

$n = "dddddddd";
$y =  "bbbbbbbb";
$q =  "bbvccc";
$c =  "mfsdmjjioj";
$o =  "sdfdfds";
$op =  "bdfgdgdf";
$oq =  "gdfgdgteg";
$or =  "ggdvdger";
$os =  "verteved";

$xml = "<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>
<gsx:DBA>dsajkn</gsx:DBA>
<gsx:BUSPHONE>sadjsahsan</gsx:BUSPHONE>
<gsx:NAME>dsadjksan</gsx:NAME>
<gsx:CITY>sajdkajsncn</gsx:CITY>
<gsx:STATE>sdlksjdsaj</gsx:STATE>
<gsx:EMAIL>dkajslkdjsajdasj</gsx:EMAIL>
<gsx:ZIP>ascmnanjcna</gsx:ZIP>
<gsx:ADDRESS>sadhbaskjdjashjkdhas</gsx:ADDRESS>
<gsx:NOTES>ncjansjkhnkn</gsx:NOTES>

</entry>
";
echo $google->writeSheet($xml);

之前完美无缺,但现在我收到了错误

无法写入空行;改为使用删除。

提前致谢。

0 个答案:

没有答案