Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle+ API: How can I use RefreshTokens to avoid requesting access every time my app launches?
    text
    copied!<p>I'm trying to use the Google+ API to access info for the authenticated user. I've copied some code from one of the samples, which works fine (below), however I'm having trouble making it work in a way I can reuse the token across app-launches.</p> <p>I tried capturing the "RefreshToken" property and using <code>provider.RefreshToken()</code> (amongst other things) and always get a <code>400 Bad Request</code> response.</p> <p>Does anyone know how to make this work, or know where I can find some samples? The <a href="http://code.google.com/p/google-api-dotnet-client/wiki/APIs#Google+_API">Google Code site</a> doesn't seem to cover this :-(</p> <pre><code>class Program { private const string Scope = "https://www.googleapis.com/auth/plus.me"; static void Main(string[] args) { var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); provider.ClientIdentifier = "BLAH"; provider.ClientSecret = "BLAH"; var auth = new OAuth2Authenticator&lt;NativeApplicationClient&gt;(provider, GetAuthentication); var plus = new PlusService(auth); plus.Key = "BLAH"; var me = plus.People.Get("me").Fetch(); Console.WriteLine(me.DisplayName); } private static IAuthorizationState GetAuthentication(NativeApplicationClient arg) { // Get the auth URL: IAuthorizationState state = new AuthorizationState(new[] { Scope }); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); Uri authUri = arg.RequestUserAuthorization(state); // Request authorization from the user (by opening a browser window): Process.Start(authUri.ToString()); Console.Write(" Authorization Code: "); string authCode = Console.ReadLine(); Console.WriteLine(); // Retrieve the access token by using the authorization code: return arg.ProcessUserAuthorization(authCode, state); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload