I updated from 1.1.5 to 2.0 and I cannot get it to login. I followed the UPGRADE.md instructions, on how to upgrade from using "setAssertionCredentials", but I can't get it to work.
BEFORE:
$client = new Google_Client();
$client->setApplicationName('API Project');
$client->setAssertionCredentials(
new Google_Auth_AssertionCredentials(
GAPI_SERVICE_ACCOUNT, array($service), file_get_contents(GAPI_KEYFILE)
)
);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
};
$client->setClientId(GAPI_CLIENT_ID);
$service = Google_Service_Webmasters($client);
AFTER:
$client = new Google_Client();
$client->setApplicationName('API Project');
$client->setDeveloperKey(GAPI_KEY);
$client->setSubject(GAPI_SERVICE_ACCOUNT);
$scopes = [ Google_Service_Webmasters::WEBMASTERS ];
$client->setAuthConfig('client_secret.json');
$client->setScopes($scopes);
$service = Google_Service_Webmasters($client);
And I get this Exception when I'm doing $service->searchanalytics->query(........)
:
object(Google_Service_Exception)#53 (8) {
["errors":protected]=>
array(1) {
[0]=>
array(5) {
["domain"]=>
string(6) "global"
["reason"]=>
string(8) "required"
["message"]=>
string(14) "Login Required"
["locationType"]=>
string(6) "header"
["location"]=>
string(13) "Authorization"
}
}
["message":protected]=>
string(238) "{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
...
I also get these notices:
PHP Notice: Undefined index: client_secret in google-api-php-client/vendor/google/apiclient/src/Google/Client.php on line 862
Notice: Undefined index: client_secret in google-api-php-client/vendor/google/apiclient/src/Google/Client.php on line 862
Any ideas? Thanks!
来源:https://stackoverflow.com/questions/37942676/setassertioncredentials-on-google-api-php-client-2-0