title: Authorizing command line tool to consume Google APIs (through OAuth2.0 or anything else)
body: <p>I <em>think</em> I understand how OAuth 2.0 works in the context of a mobile app or website - neither is my case.</p>
  
  <p>I have a C++ <strong>command line</strong> application that I want to give access to one of the Google Services (<a href="https://developers.google.com/fusiontables/" rel="noreferrer">Google Fusion Tables</a>) but I think this question applies to any of the Google Services, or heck, perhaps also any command line app that has to deal with OAuth2.</p>
  
  <p>I have the username. I have the password (the user typed it). I need to get a token so I can make the calls through Curl. What is the easiest way to accomplish this?</p>
  
  <p><strong>Update 1:</strong> </p>
  
  <p>After going through the documentation, it seems that the least painful OAuth2 flow will be the <a href="https://developers.google.com/accounts/docs/OAuth2InstalledApp" rel="noreferrer">"Installed Application"</a> one.</p>
  
  <p>What I am thinking is that my command line tool will make requests for public tables without needing a token (but it seems we still need to be sending an AppID from Google which I can get from the Google APIs dashboard).</p>
  
  <p>Whenever my command line tool will need to use a private resource, that user would be required to supply a Google supplied <em>authorization code</em> (which my command line tool can then use to get a usable <em>token</em>). If the user has not supplied the <em>authorization code</em> in the command line, my tool would just print a link that the user can paste to the URL to generate the authorization code. The link would look like this:</p>
  
  <p><a href="https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/fusiontables&amp;redirect_uri=urn:ietf:wg:oauth:2.0:oob&amp;response_type=code&amp;client_id=812741506391-h38jh0j4fv0ce1krdkiq0hfvt6n5amrf.apps.googleusercontent.com" rel="noreferrer">https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/fusiontables&amp;redirect_uri=urn:ietf:wg:oauth:2.0:oob&amp;response_type=code&amp;client_id=812741506391-h38jh0j4fv0ce1krdkiq0hfvt6n5amrf.apps.googleusercontent.com</a></p>
  
  <p>Once the user accepts, she would have to paste that <em>authorization code</em> to the terminal so it can be used by the command line tool. The command line tool would use the authorization code to ask Google for a <em>token</em> and then, finally, I can then use the Google token to make the API calls.</p>
  
  <p>A few things are still unclear to me. Does the authorization code change? If so, it seems I would need to save the token and refresh tokens somewhere so I can reuse the refresh token every time the token expires.</p>
  
  <p>Is it just me, or does this whole thing seems like crazy talk just so that I can use a Google API from the command line?</p>
  
  <p>I would normally use the <a href="https://developers.google.com/accounts/docs/AuthForInstalledApps" rel="noreferrer">ClientLogin flow</a>, but everything seems to point out that it will be deprecated soon.</p>