以“服务帐户"身份连接到Google Sites API; [英] Connecting to the Google Sites API as a "Service Account"

查看:56
本文介绍了以“服务帐户"身份连接到Google Sites API;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Google协作平台帐户(Google应用)中读取供稿. 我不需要我的应用程序要求每个用户都登录,所以我在"Google API控制台"中将ClientID创建为服务帐户". 我已将此客户端ID和范围(https://sites.google.com/feeds/)添加到了Google Apps控制面板中的管理API客户端访问权限"页面.

I am trying to read a feed from a Google Sites account (Google apps). I don't need my app to require every user to login so i created my ClientID as a "Service Account" in the "Google API console". I have added this Client ID and the scope (https://sites.google.com/feeds/) to the "Mange API client access" page in my google apps control panel.

我使用下面的代码进行连接,所有常量都在我的代码中定义了正确的值.

I connect using the code below, all constants are defined in my code with the right values.

// 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>";

我得到的答复是未获得访问此供稿的权限" 当我尝试使用我的Google Apps帐户登录OAuth2.0操场获取此供稿时,得到了预期的响应. 我在这里俯瞰什么?

The response i get is "Not authorized to access this feed " When i try to get this feed in the OAuth2.0 playground logging in using my google apps account i get the expected response. What am i overlooking here?

推荐答案

服务帐户和Google协作平台目前无法一起使用. Google Apps提供了一个消费者机密,可用于在OAuth 1.0a中以跨两步OAuth的方式访问您整个域中的数据.

Service accounts and Google Sites can't be used together currently. Google Apps provides a consumer secret that can be used to access data across your domain as Two-Legged OAuth within OAuth 1.0a.

签出 http://support.google.有关如何配置您的Apps帐户的com/a/bin/answer.py?hl = zh-CN& answer = 162105 以及位于 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆