2012-10-22 5 views
1

Google 사이트 도구 계정 (Google 앱)에서 피드를 읽으려고합니다. "Google API 콘솔"의 "서비스 계정"으로 ClientID를 만들 때 모든 사용자가 로그인하도록 내 앱을 요구하지 않아도됩니다. Google 애플 리케이션 제어판의 "Mange API 클라이언트 액세스"페이지에이 클라이언트 ID와 범위 (https://sites.google.com/feeds/)를 추가했습니다.Google 사이트 도구 API에 "서비스 계정"으로 연결

아래 코드를 사용하여 연결하면 모든 상수가 올바른 값으로 내 코드에 정의됩니다. 내 Google 애플 리케이션을 사용하여에 OAuth2.0에 놀이터 로깅이 피드를 얻을 때

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

내가 얻을 응답은 "이 피드에 액세스 할 수있는 권한이 없습니다"입니다 내가 예상 응답을 차지하고있다. 여기에서 무엇을 내려다 볼 수 있습니까?

답변

4

서비스 계정과 Google 사이트 도구는 현재 함께 사용할 수 없습니다. Google Apps는 OAuth 1.0a 내에서 Two-Legged OAuth로 도메인 전체의 데이터에 액세스하는 데 사용할 수있는 고객 비밀번호를 제공합니다.

Apps 계정을 구성하는 방법은 http://support.google.com/a/bin/answer.py?hl=en&answer=162105을 확인하고 샘플 코드는 https://developers.google.com/gdata/docs/auth/oauth#2LeggedOAuth으로 확인하십시오.