Неверный JSON в ответе сервиса

Я пытаюсь получить информацию о своем профиле с помощью PHP API, но, похоже, она не работает в последние пару дней.

Мой код выглядит следующим образом:

<?php
try {
$client_id = '****************.apps.googleusercontent.com';
$client_secret = '*********************';
$redirect_uri = '**********************';
$google_key = '***************';

$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->setDeveloperKey($google_key);
$client->setAccessType('offline');
$client->setScopes(array('https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile'));
$plus = new Google_Service_Plus($client);

if(isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$accessToken = $client->getAccessToken();
$refreshToken = json_decode($accessToken)->refresh_token;
setcookie('refresh_token', $refreshToken, (time()+60*60*24*30));
setcookie('access_token', $accessToken, (time()+60*60*24*30));
header('Location: ./');
exit();
}

if(isset($_COOKIE['access_token']) && $_COOKIE['access_token']) {
$refreshToken = json_decode($_COOKIE['access_token'])->refresh_token;
$accessToken = $_COOKIE['access_token'];
setcookie('access_token', $accessToken, (time()+60*60*24*30));
$client->setAccessToken($_COOKIE['access_token']);
} else {
$authUrl = $client->createAuthUrl();
}

if($client->getAccessToken()) {
$accessToken = $client->getAccessToken();
setcookie('access_token', $accessToken, (time()+60*60*24*30));
if(isset($plus)){
$userInfo = $plus->people->get('me');
}
}

if($client->isAccessTokenExpired() && isset($userInfo)){
$refreshToken = $_COOKIE['refresh_token'];
$client->refreshToken($refreshToken);
$newtoken = $client->getAccessToken();
setcookie('access_token', $newtoken, (time()+60*60*24*30));
header('Location: ./');
exit();
}

} catch (Google_Service_Exception $gse){
error_log($gse, 0);
} catch (Google_Auth_Exception $gae){
error_log($gae, 0);
}
?>

Я скоро буду использовать базу данных, но я бы хотел, чтобы она сначала работала с файлами cookie. Я получаю следующую ошибку:

[05-Aug-2015 20:40:36 Europe/London] exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/plus/v1/people/me?key=**********************: (403) ‹' in /home5/commodit/public_html/workflow/src/Google/Http/REST.php:110
Stack trace:
#0 /home5/commodit/public_html/workflow/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client))
#1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request))
#2 /home5/commodit/public_html/workflow/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array)
#3 /home5/commodit/public_html/workflow/src/Google/Http/REST.php(46): Google_Task_Runner->run()
#4 /home5/commodit/public_html/workflow/src/Google/Client.php(593): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#5 /home5/commodit/public_html/workflow/src/Google/Service/Resource.php(237): Google_Client->execute(Object(Google_Http_Request))
#6 /home5/commodit/public_html/workflow/src/Google/Service/Plus.php(562): Google_Service_Resource->call('get', Array, 'Google_Service_...')
#7 /home5/commodit/public_html/workflow/includes/head.php(87): Google_Service_Plus_People_Resource->get('me')
#8 /home5/commodit/public_html/workflow/index.php(4): include('/home5/commodit...')
#9 {main}

Я также получаю «Ответ недействительный json», если я пытаюсь использовать OAuth2 вместо Google Plus в качестве службы.

[05-Aug-2015 20:46:02 Europe/London] exception 'Google_Service_Exception' with message 'Invalid json in service response: ‹' in /home5/commodit/public_html/workflow/src/Google/Http/REST.php:125
Stack trace:
#0 /home5/commodit/public_html/workflow/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client))
#1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request))
#2 /home5/commodit/public_html/workflow/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array)
#3 /home5/commodit/public_html/workflow/src/Google/Http/REST.php(46): Google_Task_Runner->run()
#4 /home5/commodit/public_html/workflow/src/Google/Client.php(593): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#5 /home5/commodit/public_html/workflow/src/Google/Service/Resource.php(237): Google_Client->execute(Object(Google_Http_Request))
#6 /home5/commodit/public_html/workflow/src/Google/Service/Oauth2.php(175): Google_Service_Resource->call('get', Array, 'Google_Service_...')
#7 /home5/commodit/public_html/workflow/includes/head.php(89): Google_Service_Oauth2_Userinfo_Resource->get()
#8 /home5/commodit/public_html/workflow/index.php(4): include('/home5/commodit...')
#9 {main}

Спасибо за любую помощь!
Бетани

P.S. Я также попробовал переменную «opt_params», но она все еще говорит, что неверный JSON 🙁

0

Решение

Я предлагаю проверить файл Google / Config.php, есть несколько параметров по умолчанию, которые можно настроить, чтобы получить решение для различных проблем.

В моем случае я также получал неверный-json-in-service-response, я был уверен в правильных настройках учетных данных, я пытался запустить URL, который был передан в Google API с протоколом GET и строкой запроса, и всегда имел полный текст текст в формате ответа json, поэтому я посмотрел на параметр «disable_gzip» и изменил его, чтобы увидеть поведение при изменении.

'Google_Http_Request' => array(
// Disable the use of gzip on calls if set to true. Defaults to false.
'disable_gzip' => self::GZIP_DISABLED, //self::GZIP_ENABLED,

// We default gzip to disabled on uploads even if gzip is otherwise
// enabled, due to some issues seen with small packet sizes for uploads.
// Please test with this option before enabling gzip for uploads in
// a production environment.
'enable_gzip_for_uploads' => self::GZIP_UPLOADS_DISABLED,
),

Вы можете установить разные значения для Google_Client Config, Class Attribute, вызывающего определенный метод.

public function setClassConfig($class, $config, $value = null)
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector