使用 Zend_Gdata_Spreadsheets 进行公共电子表格?
我有这段代码正在运行,可以加载 Google 电子表格并从中加载一些数据。如果相关电子表格是公开的,我如何修改代码以不需要用户名/密码?
$key="keytothespreadsheet";
$user="[email protected]";
$pass="*****";
$authService = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $authService);
$gdClient = new Zend_Gdata_Spreadsheets($httpClient);
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($key);
$feed = $gdClient->getWorksheetFeed($query);
print_r($feed);
I have this code which is working, to load a Google Spreadsheet and load some data from it. If the spreadsheet in question is public, how do i modify the code to not require a username/password?
$key="keytothespreadsheet";
$user="[email protected]";
$pass="*****";
$authService = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $authService);
$gdClient = new Zend_Gdata_Spreadsheets($httpClient);
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($key);
$feed = $gdClient->getWorksheetFeed($query);
print_r($feed);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在下面的行中,HTTP 客户端是可选的:
所以,不要传递它。以下是等效的:
In the following line, the HTTP client is optional:
So, just don't pass it. The following are equivalent:
和@Matt 一样,我想在不提供凭据的情况下访问公共电子表格。感谢@Derek Illchuk,我已经完成了部分工作。然而,它仍然无法工作,直到我了解了以下内容:
请注意,文件> >发布到网络功能与共享设置>不同。在网络上公开。如果您忘记启用“发布到网络”,您将收到以下错误:“预期响应代码 200,收到 400 无法找到此 URL 上的电子表格。请确保您拥有正确的 URL,并且电子表格的所有者尚未删除它。”
在“发布到网络”设置中,请务必取消选中“要求查看者使用他们的___ 帐户。”。否则,您将收到此错误:“预期响应代码 200,收到 403 您无权查看电子表格。请确保您经过正确身份验证。”
根据 Google 文档,“电子表格 Feed 仅支持“私有”可见性和“完整”投影”。但是,我发现我需要指定“公共”可见性和“基本”投影。否则我会得到这个错误:
“预期响应代码 200,收到 501 此类操作的投影错误或不受支持。”
以下是对我有用的内容:
Like @Matt, I wanted to access a public spreadsheet without supplying credentials. Thanks to @Derek Illchuk, I got part of the way there. It still wasn't working, however, until I learned the following:
Note that the File > Publish to the Web feature is not the same thing as Sharing Settings > Public On The Web. If you forget to enable "Publish to the Web", you'll get this error: "Expected response code 200, got 400 The spreadsheet at this URL could not be found. Make sure that you have the right URL and that the owner of the spreadsheet hasn't deleted it."
In the "Publish to the Web" settings, be sure to uncheck "Require viewers to sign in with their ___ account.". Otherwise you'll get this error: "Expected response code 200, got 403 You do not have view access to the spreadsheet. Make sure you are properly authenticated."
According to Google's documentation, "The spreadsheets feed only supports the 'private' visibility and the 'full' projection." However, I found that I needed to specify 'public' visibility and 'basic' projection. Otherwise I got this error:
"Expected response code 200, got 501 Bad or unsupported projection for this type of operation."
Here is what worked for me: