【发布时间】:2012-10-23 06:31:11
【问题描述】:
我正在尝试从 Google 协作平台帐户(Google 应用程序)读取供稿。 我不需要我的应用程序要求每个用户登录,所以我在“Google API 控制台”中将我的 ClientID 创建为“服务帐户”。 我已将此客户端 ID 和范围 (https://sites.google.com/feeds/) 添加到我的谷歌应用程序控制面板中的“管理 API 客户端访问”页面。
我使用下面的代码进行连接,所有常量都在我的代码中定义了正确的值。
// api dependencies
require_once(GOOGLE_API_PATH);
// create client object and set app name
$client = new Google_Client();
$client->setApplicationName(GOOGLE_API_NAME);
// set assertion credentials
$client->setAssertionCredentials(
new Google_AssertionCredentials(
GOOGLE_API_EMAIL,
array(GOOGLE_API_SCOPE),
file_get_contents(GOOGLE_API_PK)
));
$client->setClientId(GOOGLE_API_CLIENTID);
// create service
$req = new Google_HttpRequest("https://sites.google.com/feeds/content/<herismydomainname.com>/intranet");
$val = $client->getIo()->authenticatedRequest($req);
// The contacts api only returns XML responses.
$response = json_encode($val->getResponseBody());
print "<pre>" . print_r(json_decode($response, true), true) . "</pre>";
我得到的响应是“无权访问此提要” 当我尝试在 OAuth2.0 操场上使用我的谷歌应用程序帐户登录时获取此提要时,我得到了预期的响应。 我在这里俯瞰什么?
【问题讨论】:
-
我也在寻找一种方法来读取 Google 协作平台帐户的提要,只是想知道这是否找到了解决方案。
标签: php google-api oauth-2.0 google-sites google-oauth