2012-10-22 167 views
1

我在嘗試從Google協作平臺帳戶(Google應用)閱讀供稿。 我不需要我的應用程序來要求每個用戶登錄,因此我在「Google API控制檯」中將我的ClientID創建爲「服務帳戶」。 我已將此客戶ID和範圍(https://sites.google.com/feeds/)添加到我的谷歌應用程序控制面板中的「Mange API客戶端訪問」頁面。以「服務帳戶」身份連接到Google Sites 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的操場上記錄使用我的谷歌Apps帳戶我得到預期的響應。 我在這裏俯瞰什麼?

回答

相關問題