title: Google API oAuth 2.0 - script run from command line
body: <p>I want to run a daily cronjob to load data from Google Analytics into my database. I want to use PHP and oAuth 2.0.</p>
  
  <p>I assume that this case would be considered a Web Server Application (<a href="https://developers.google.com/accounts/docs/OAuth2?hl=de#webserver" rel="nofollow noreferrer">https://developers.google.com/accounts/docs/OAuth2?hl=de#webserver</a>)</p>
  
  <p>But in all examples I find it uses the typical, a user clicks on a 'connect to Google' button, browser rediretcs to Google where the user has to login and authorize the request.</p>
  
  <p>But I want to run this from the command line and the user is always me. I guess this is not very diferente from the browser approach but I am a little confused on where to start neither how to formulate this into a real question.</p>
  
  <p>Does anyone have tutorials especificaly about this or any other help?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: The first time I have to get the token and the refresh token. Is there any other may to get this then over the google popup in the browser? Or do I have to make a little html page to run this once to get the token and refresh token? Still confused.</p>
  
  <p><img src="https://i.stack.imgur.com/BmF2b.png" alt="enter image description here"></p>