Google Analytics PHP Interface (GAPI) OAuth 2.0 token expiring

173 views Asked by At

I'm currently using the GAPI tool to extract date from my Google Analytics account using an OAuth 2.0 account created in the Google Developers Console. It works flawlessly except for one thing - every so often, the script will fail with the following message:

'GAPI: Failed to request report data. Error: "{"error":{"errors":[{"domain":"global","reason":"authError","message":"Invalid Credentials","locationType":"header","location":"Authorization"}],"code":401,"message":"Invalid Credentials"}}" 

My assumption is that the Oauth 2.0 token is expiring, preventing further data access. I have been manually restarting the process so far, but it would be far more efficient to automatically refresh the token prior to expiration. If anyone knows the best way to accomplish this, I'd appreciate hearing it. Thanks.

0

There are 0 answers