Google Analytics API v3 authorization to allow access to my data

前端 未结 3 803
既然无缘
既然无缘 2021-02-13 14:14

I am developing an app that allows users to see my own Google Analytics Data using Google API v3. Everything I researched seems to indicate that users need to login into their G

3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-13 15:18

    Here is a full Google Analytics reporting example implementation with service account including setup notes. Just wrote it after reading your question, I had the same problem.

    setScopes(array(SCOPE));
    $client->setAssertionCredentials($auth);
    $client->getAuth()->refreshTokenWithAssertion();
    $accessToken = $client->getAccessToken();
    $client->setClientId(CLIENT_ID);
    $service = new Google_Service_Analytics($client);
    
    ?>
    
    
      
        Google Experiments Dashboard
        
        
      
      
        

    Your experiments

    "; if ($experiment['status'] == 'RUNNING') echo '
    ExperimentPageStartedStatus management_profiles->listManagementProfiles("~all", "~all"); foreach ($profiles['items'] as $profile) { $experiments = $service->management_experiments->listManagementExperiments($profile['accountId'], $profile['webPropertyId'], $profile['id']); foreach ($experiments['items'] as $experiment) { echo "
    '; else echo ''; $expHref = "https://www.google.com/analytics/web/?pli=1#siteopt-experiment/siteopt-detail/a{$profile['accountId']}w{$experiment['internalWebPropertyId']}p{$experiment['profileId']}/%3F_r.drilldown%3Danalytics.gwoExperimentId%3A{$experiment['id']}/"; echo "{$experiment['name']}"; echo "{$experiment['variations'][0]['url']}"; echo "".date('Y-m-d',strtotime($experiment['startTime'])); echo ""; echo '
    '; foreach ($experiment['variations'] as $i => $variation) { echo '
    '.$variation['name'].'
    '; } echo '
    '; } } ?>

    Code with more documentation at https://gist.github.com/fulldecent/6728257

    提交回复
    热议问题