0

I'm currently creating a tool to help me create google analytics daily reports easily. To do this, I need to access google analytics data at specific hours and days (for example, each day at 9am and 9pm), server side (PHP, Laravel).

The problem is that when I use the OAuth 2 authentication method, I need to re-login each time I want to access data (i need to redirect the user, and wait for redirection to get the code, and use it to get a token). I can use the "service account" method, but it implies to use a .p12 certificate, which is not sustainable in production (i can't ask my users to upload their certificates files).

Do you know a way, or have you an idea, to access analytics data without having to relogging (ideally with oauth...) or using service account method (with a certificate file) ?

Thank you

  • You need to set the offline access to true: https://developers.google.com/identity/protocols/OAuth2WebServer?hl=en#offline – Matt Jan 07 '16 at 04:33
  • Possible duplicate of [How to use refresh token to get authorized in background and getting access token?](http://stackoverflow.com/questions/33870439/how-to-use-refresh-token-to-get-authorized-in-background-and-getting-access-toke) – Prafulla Kumar Sahu Jan 11 '16 at 10:58
  • @Matt check the post I have marked your post as duplicate of, that is doing that part, you need to store the refresh token, either in cookies, cache or database and using that you will authorize your application in background , that is how it is done. – Prafulla Kumar Sahu Jan 11 '16 at 11:00
  • You shouldn't have to ask users to upload certificate files. You should be able to do this by having them authenticate/authorize once. You then get an "Refresh Token". You then use this Refresh Token to get Access Tokens that live for 1 hour. – M Schenkel Jan 12 '16 at 01:19

0 Answers0