2012-01-29 33 views
2

私はa small card game for Google+に訪問者の名前、アバター、性別、都市が必要です。'apiServiceException'というキャッチされた例外 'GET ....を呼び出すときにエラーが発生しました。'

それは自分自身のために動作しますが、error_logにして、私はPHP-例外の多くを参照してください。ここで

[28-Jan-2012 19:06:33] PHP Fatal error: Uncaught exception 'apiServiceException' with message 'Error calling GET https://www.googleapis.com/plus/v1/people/me?alt=json&key=AIzaSyAgQl0UeNM553PfLnPmP0jTtcJ8ZIQ3q0g: (404) Not Found' in /var/www/html/preferans.de/google/google-api-php-client/src/io/apiREST.php:86 
Stack trace: 
#0 /var/www/html/preferans.de/google/google-api-php-client/src/io/apiREST.php(56): apiREST::decodeHttpResponse(Object(apiHttpRequest)) 
#1 /var/www/html/preferans.de/google/google-api-php-client/src/service/apiServiceResource.php(151): apiREST::execute(Object(apiServiceRequest)) 
#2 /var/www/html/preferans.de/google/google-api-php-client/src/contrib/apiPlusService.php(207): apiServiceResource->__call('get', Array) 
#3 /var/www/html/preferans.de/google/index.php(33): PeopleServiceResource->get('me') 
#4 {main} 
    thrown in /var/www/html/preferans.de/google/google-api-php-client/src/io/apiREST.php on line 86 

は私のスクリプトです:

<?php 

require_once('google-api-php-client/src/apiClient.php'); 
require_once('google-api-php-client/src/contrib/apiPlusService.php'); 

session_start(); 

$client = new apiClient(); 
$client->setApplicationName('Video-Preferans'); 
$client->setClientId('XXX.apps.googleusercontent.com'); 
$client->setClientSecret('XXX'); 
$client->setRedirectUri('http://preferans.de/google'); 
$client->setDeveloperKey('XXX'); 
$client->setScopes(array('https://www.googleapis.com/auth/plus.me')); 
$plus = new apiPlusService($client); 

if (isset($_REQUEST['logout'])) 
     unset($_SESSION['access_token']); 

if (isset($_GET['code'])) { 
     $client->authenticate(); 
     $_SESSION['access_token'] = $client->getAccessToken(); 
     header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); 
} 

if (isset($_SESSION['access_token'])) 
     $client->setAccessToken($_SESSION['access_token']); 

if ($client->getAccessToken()) { 
     $me = $plus->people->get('me'); # XXX line 33 XXX 
     # the access token may have been updated lazily 
     $_SESSION['access_token'] = $client->getAccessToken(); 
} else { 
     printf(' 
<!doctype html> 
<html> 
<head> 
<body> 
<p><a href="%s">Play Preferans</a></p> 
</body> 
</html> 
', $client->createAuthUrl()); 
     exit(); 
} 

$viewer_id = $me['id']; 
list($first_name, $last_name) = explode(' ', $me['displayName']); 
$city  = $me['placesLived'][0]['value']; 
$female = ($me['gender'] == 'male' ? 0 : 1); 
$avatar = $me['image']['url']; 

....skipped some html code.... 

誰もが知って下さいん、なぜapiServiceExceptionがスローされていますか?

私はそれをよりよくデバッグできるように、どうやって少なくともそれをキャッチしていますか?

私はthe latest Google+ SDK 0.4.8.3を使用していますが、私は非常に基本的なユーザー情報を要求しています。私が書いたように、それは私にとっても妻のアカウントでも機能します。

答えて

3

try/catchブロック内で$ me = $ plus-> people-> get( 'me')をラップすることができます。

プラス/ V1 /人/私APIは、ユーザーがGoogle+に登録されていない、とあなたは以下でこのケースをキャッチすることができたときに見つからない404を返します。

try { 
    $me = $plus->people->get('me') 
} catch (apiServiceException $e) { 
    // Handle exception. You can also catch Exception here. 
    // You can also get the error code from $e->getCode(); 
} 
+0

ブロックをキャッチ私 – dspacejs

1

私は同じ問題を抱えています違いは、私はカレンダーAPIを使用しようとしていることだけです。あなたが最初にやったのと全く同じエラーレスポンスを得て、try/catch-blockを試してみました。エラーレスポンスを出力すると "403"と表示されますが、JSONレスポンスも得られます。なぜなのかご存知ですか?

私のコード:私は403エラーを取得上記をやってみたときに

if ($client->getAccessToken()) { 
    try{ 
     $activities = $plus->activities->listActivities('me', 'public'); 
     print 'Your Activities: <pre>' . print_r($activities, true) . '</pre>'; 

     // The access token may have been updated. 
     $_SESSION['token'] = $client->getAccessToken(); 
    } catch (apiServiceException $e) { 
     // Handle exception. You can also catch Exception here. 
     // You can also get the error code from $e->getCode(); 
     echo $e->getCode(); 
     print_r($activities); 
    } 

} 
+0

のために動作しませんでした。どういう意味ですか ? –

関連する問題