Код: Выделить всё
require_once('autoload.php');
require_once('Client.php');
$client = new Google_Client();
$client->setClientId('my clientid');
$client->setClientSecret('my secret');
$client->setDeveloperKey('my developer key');
$client->setApprovalPrompt('auto');
$client->setAccessType('offline');
$client->setRedirectUri(null);
$client->setScopes(array('https://www.googleapis.com/auth/userinfo.profile','https://www.googleapis.com/auth/analytics'));
$service = new Google_Service_Analytics($client);
// get accounts from analytics
$accounts = $service->management_accounts->listManagementAccounts();
Неустранимая ошибка PHP: необработанное исключение «Google_Service_Exception» с
сообщением
'{"error":{"errors":[{"domain":"global","reason":"required","message":"Login
Required","locationType":"header","location":"Authorization"}],"code":401,"message":"Login
Требуется"}}' в
/root/google-api/google-api-php-client-2.0.0-RC5/src/Google/Http/REST.php:129
Трассировка стека:
#0 /root/google-api/google-api-php-client-2.0.0-RC5/src/Google/Http/REST.php(88):
Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response),
Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#1 [внутренняя функция]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client),
Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#2 /root/google-api/google-api-php-client-2.0.0-RC5/src/Google/Task/Runner.php(181):
call_user_func_array(Array, Array)
#3 /root/google-api/google-api-php-client-2.0.0-RC5/src/Google/Http/REST.php(57):
Google_Task_Runner->run()
#4 /root/google-api/google-api-php-client-2.0.0-RC5/src/Google/Client.php(758):
Google_Http_REST::execute(Object(GuzzleH in
/root/google-api/google-api-php-client-2.0.0-RC5/src/Google/Http/REST.php
в строке 129
Почему?
Подробнее здесь: https://stackoverflow.com/questions/358 ... le-api-php
Мобильная версия