2014-07-01 1 views
1

코드를 작동 시키려고 벽에서 머리를 숙였습니다. 리디렉션 URL과 함께 인증 경로를 사용하여 Google Api에 이미 성공적으로 연결했습니다.인증 Google 콘텐츠 API 서비스 계정 - '사용자가 계정에 액세스 할 수 없습니다'오류가 발생했습니다.

그러나이 작업을 crontab에서 실행되는 독립형 서비스로 사용해야합니다.

이제 '서비스 계정'으로 인증하려고합니다.

이것은 내 코드이며 아래에 나와있는 오류를 찾을 수 있습니다.

$client = new Google_Client(); 
$client->setApplicationName('GoogleShoppingService'); 

if (isset($_SESSION['service_token'])) { 
    $client->setAccessToken($_SESSION['service_token']); 
} 

$service = new Google_Service_Content($client); 

$client_id = 'xxxxxxx.apps.googleusercontent.com'; 
$client->setClientId($client_id); 
$service_account_name = '[email protected]'; 


$key_file_location = 'privatekey.p12'; 
$key = file_get_contents($key_file_location); 
$scope = 'https://www.googleapis.com/auth/content'; 
$cred = new Google_Auth_AssertionCredentials(
    $service_account_name, 
     array($scope), 
     $key 
    ); 
$result = $client->setAssertionCredentials($cred); 
print_r($result); 
if($client->getAuth()->isAccessTokenExpired()) { 
    $client->getAuth()->refreshTokenWithAssertion($cred); 
} 

$_SESSION['service_token'] = $client->getAccessToken(); 
echo $client->getAccessToken(); 

$merchantId = 1234567;//this a dummy value, I replace it with the actual merchantId 
$accountId = 1234567;//this a dummy value, I replace it with the actual accountId 
$accountstatuses = $service->accountstatuses->get($merchantId,$accountId); 

코드를 실행할 때 표시되는 메시지입니다. (토큰이 생성되어 있습니다,하지만 난 구글 쇼핑 피드의 콘텐츠에 액세스 할 수 없습니다 오전.)

{"access_token":"ya29.NQD7MQz0cas9PhoAAADRPMlTVecqYXYh4fNoZfRMymQtSF4hwqJn31uobohLbw","expires_in":3600,"created":1404200605} 
Fatal error: 
Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/content/v2/1234567/accountstatuses/1234567: (401) User cannot access account 1234567' in /home/sites/site1/web/googleShopping2/src/Google/Http/REST.php:79 
Stack trace: 
#0 /home/sites/site1/web/googleShopping2/src/Google/Http/REST.php(44): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request)) 
#1 /home/sites/site1/web/googleShopping2/src/Google/Client.php(499): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request)) 
#2 /home/sites/site1/web/googleShopping2/src/Google/Service/Resource.php(195): Google_Client->execute(Object(Google_Http_Request)) 
#3 /home/sites/site1/web/googleShopping2/src/Google/Service/Content.php(685): Google_Service_Resource->call('get', Array, 'Google_Service_...') 
#4 /home/sites/site1/web/googleShopping2/examples/test.php(58): Google_Service_Content_Accountstatuses_Resource->get(1234567, 1234567) 
#5 {main} thrown in /home/sites/site1/web/googleShopping2/src/Google/Http/REST.php on line 79 

은 이미 지금 이일에 대한 해결책을 찾기 위해 노력했지만, 어떤 힌트가 나는 나를 도와주지 않는다는 것을 발견했다. 또한 새로운 Api 인증 키를 사용하여 새 프로젝트를 만들었지 만 아무 것도 작동하지 않고 항상 위의 메시지를받습니다. 누가 나를 도울 수 있습니까?

감사합니다, 마틴

답변

5

당신은 당신이 설정에서 구글 상인 계정> 사용자에 만든 서비스 계정의 이메일 주소를 추가해야합니다.

관련 문제