【问题标题】:PHP Google API Client updating library problemPHP Google API 客户端更新库问题
【发布时间】:2019-01-22 08:38:43
【问题描述】:

我必须将google/apiclient1.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 版的此代码?

【问题讨论】:

    标签: php google-api google-oauth google-api-php-client google-php-sdk


    【解决方案1】:

    以下代码来自我的示例项目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); 
    

    【讨论】:

      猜你喜欢
      • 2016-12-03
      • 2017-07-29
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多