Han*_*ijk 2 php google-api google-sites oauth-2.0 google-oauth
我正在尝试从Google协作平台帐户(Google应用)中读取Feed.我不需要我的应用程序要求每个用户登录,因此我在"Google API控制台"中将我的ClientID创建为"服务帐户".我已将此客户ID和范围(https://sites.google.com/feeds/)添加到我的Google Apps控制面板中的"Mange 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>";
Run Code Online (Sandbox Code Playgroud)
我得到的回复是"未授权访问此Feed"当我尝试在使用我的Google Apps帐户登录的OAuth2.0游戏中获取此Feed时,我得到了预期的响应.我在这里俯瞰什么?
小智 5
目前,服务帐户和Google协作平台不能一起使用.谷歌企业应用套件提供了可用于跨域访问数据OAuth的1.0A内双向OAuth消费者的秘密.
退房http://support.google.com/a/bin/answer.py?hl=en&answer=162105关于如何配置你的Apps帐户,并在示例代码https://developers.google.com/gdata/ docs/auth/oauth#2LeggedOAuth.
归档时间: |
|
查看次数: |
2233 次 |
最近记录: |