我需要将 html 表单/调查的结果发布到 google docs 电子表格。现在我正在尝试使用 api 的最简单方案,它只是在我的电子表格中写入一个简单的行,尽管我不断收到错误消息。(我对php不太擅长,所以请多多包涵!)
代码:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "$_SERVER[DOCUMENT_ROOT]/ZendGdata-1.12.1/library");
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$user = "######";
$pass = "######";
$service = "xapi";
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service, null, Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null, Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, 'GOOGLE');
$spreadsheetService = new Zend_Gdata_Spreadsheets($client);
$feed = $spreadsheetService->getSpreadsheetFeed();
foreach ($feed as $entry) {
echo 'Title: ' . $entry->title . ' - ';
echo 'Id: ' . $entry->id . '<br />';
}
$rowData = array('wood' => 'oak');
$spreadsheetKey = '######';
$worksheetId = 'od6';
try{
$insertedListEntry = $spreadsheetService->insertRow($rowData,
$spreadsheetKey,
$worksheetId);
}
catch(Zend_Gdata_App_HttpException $exception) {
echo "Error: " . $exception->getResponse()->getRawBody();
}
?>
</body>
</html>
错误:
> Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with
> message 'Expected response code 200, got 401 <HTML> <HEAD>
> <TITLE>Token invalid</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF"
> TEXT="#000000"> <H1>Token invalid</H1> <H2>Error 401</H2> </BODY>
> </HTML> ' in
> C:\xampp\htdocs\ZendGdata-1.12.1\library\Zend\Gdata\App.php:714 Stack
> trace: #0
> C:\xampp\htdocs\ZendGdata-1.12.1\library\Zend\Gdata.php(219):
> Zend_Gdata_App->performHttpRequest('GET', 'https://spreads...', Array,
> NULL, NULL, NULL) #1
> C:\xampp\htdocs\ZendGdata-1.12.1\library\Zend\Gdata\App.php(880):
> Zend_Gdata->performHttpRequest('GET', 'https://spreads...', Array) #2
> C:\xampp\htdocs\ZendGdata-1.12.1\library\Zend\Gdata\App.php(768):
> Zend_Gdata_App->get('https://spreads...', NULL) #3
> C:\xampp\htdocs\ZendGdata-1.12.1\library\Zend\Gdata\App.php(210):
> Zend_Gdata_App->importUrl('https://spreads...', 'Zend_Gdata_Spre...',
> NULL) #4 C:\xampp\htdocs\ZendGdata-1.12.1\library\Zend\Gdata.php(162):
> Zend_Gdata_App->getFeed('https://spreads...', 'Zend_Gdata_Spre...') #5
> C:\xa in C:\xampp\htdocs\ZendGdata-1.12.1\library\Zend\Gdata\App.php
> on line 714
任何帮助表示赞赏!:]