我必须将google/apiclient
软件包1.0.*@dev
更新为^2.2
。
我在1.0版中有以下代码:
$this->_client = new Google_Client();
$this->_client->setAssertionCredentials(new Google_Auth_AssertionCredentials(
'__ACCOUNT__',
["https://www.googleapis.com/auth/analytics.readonly"],
file_get_contents('__PATH_TO_KEY__'))
);
$this->_client->setClientId('__CLIENT_ID__');
$this->_analytics = new Google_Service_Analytics($this->_client);
如何为2.2版替换此代码?
答案 0 :(得分:0)
以下代码来自我的示例项目Oauth2Authentication.php
$client = new Google_Client();
$client->setAccessType("offline"); // offline access. Will result in a refresh token
$client->setIncludeGrantedScopes(true); // incremental auth
$client->setAuthConfig(__DIR__ . '/client_secrets.json');
$client->addScope("https://www.googleapis.com/auth/analytics.readonly");
$client->setRedirectUri(getRedirectUri());
getOauth2Client()
$service = new Google_Service_Analytics($client);