【问题标题】:Connecting to the Google Sites API as a "Service Account"作为“服务帐户”连接到 Google 协作平台 API
【发布时间】: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


【解决方案1】:

目前不能同时使用服务帐号和 Google 协作平台。 Google Apps 提供了一个消费者机密,可用于在 OAuth 1.0a 中以两条腿式 OAuth 的形式访问您的域中的数据。

查看http://support.google.com/a/bin/answer.py?hl=en&answer=162105 了解如何配置您的应用帐户,以及https://developers.google.com/gdata/docs/auth/oauth#2LeggedOAuth 的示例代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    • 1970-01-01
    • 1970-01-01
    • 2011-11-13
    • 2022-01-17
    相关资源
    最近更新 更多