Google Analytics Core Reporting API Version 3.0 without client login

后端 未结 1 1184
庸人自扰
庸人自扰 2021-02-15 23:40

I want to access our Google Analytics account reporting using the newer v3.0, but it seems from everything that I read that in order to get a valid access token the user must lo

1条回答
  •  孤街浪徒
    2021-02-15 23:42

    I did end up using the refresh tokens, they work fine. I got a oauth token by using the google api console, and then saved it.

    Then I just do this before each request:

    require_once 'google-api-php-client/src/apiClient.php';
    require_once 'google-api-php-client/src/contrib/apiAnalyticsService.php';;
    
    $client = new apiClient();
    $client->setApplicationName('My Analytics');
    $client->setClientId($this->client_id);
    $client->setClientSecret($this->client_secret);
    $client->setDeveloperKey($this->api_key);
    
    $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
    
    $client->refreshToken($this->refresh_token);
    
    $this->service = new apiAnalyticsService($client);
    

    0 讨论(0)
提交回复
热议问题