2

Googleサイトアカウント(Googleアプリ)からフィードを読み込もうとしています。すべてのユーザーにログインを要求するアプリは必要ないので、「GoogleAPIコンソール」で「サービスアカウント」としてClientIDを作成しました。このクライアントIDとスコープ(https://sites.google.com/feeds/)をGoogleアプリのコントロールパネルの[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>";

取得した応答は「このフィードへのアクセスが許可されていません」です。GoogleAppsアカウントを使用してログインしているOAuth2.0プレイグラウンドでこのフィードを取得しようとすると、期待どおりの応答が得られます。私はここで何を見落としていますか?

4

1 に答える 1

5

現在、サービス アカウントと Google サイトを併用することはできません。Google Apps は、OAuth 1.0a 内の Two-Legged OAuth としてドメイン全体のデータにアクセスするために使用できるコンシューマ シークレットを提供します。

Apps アカウントの設定方法についてはhttp://support.google.com/a/bin/answer.py?hl=ja&answer=162105をご覧ください。サンプル コードはhttps://developers.google.com/gdata/にあります。 docs/auth/oauth#2LeggedOAuth .

于 2012-10-22T22:31:11.480 に答える