Search code examples
phpgoogle-apigoogle-oauthgoogle-analytics-apiphp-curl

Google-analytics access token


I need an access token to make API calls of google analytics. which does not expire

already I created a curl API call using the google analytics query explore but the query explorer only gives the API access token which expires after 60 min.

curl_setopt($ch, CURLOPT_URL,'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A189254231&start-date=2019-02-01&end-date=2019-02-12&metrics=ga%3Ausers&dimensions=ga%3Asource&api=AIzaSyAUoXk0LxZeciEeMdxyOyvMVLOT6Phku4w');

The am getting the results properly but after 60 mins the token expires


Solution

  • We can get a refresh token by developers.google.com/oauthplayground click on settings check Use your own OAuth credentials and enter OAuth Client ID and OAuth Client secret then select google analytics api in "select and authorize api" then we will get a refresh token.