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プレイグラウンドでこのフィードを取得しようとすると、期待どおりの応答が得られます。私はここで何を見落としていますか?