0
using (var stream =
            new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
    string credPath = System.Environment.GetFolderPath(
        System.Environment.SpecialFolder.Personal);
    credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");


    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        Scopes,
        "user",
        CancellationToken.None,
        new FileDataStore(credPath, true)).Result;
    Console.WriteLine("Credential file saved to: " + credPath);
}

This code writes the tokens to a file. I need to get the Refresh token in string format in order to save it in the database for a particular user. Please help.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Thanuja Dilhan
  • 137
  • 2
  • 10
  • Have you tried implementing `IDataStore` yourself? (That's the type of the last parameter to `AuthorizeAsync`.) – Jon Skeet Nov 03 '16 at 08:42
  • I think this [tutorial](http://www.daimto.com/google-calendar-api-authentication-with-c/) can help you to Authenticate the Google Calendar API with C#. It also shows example code here that you can follow. For more information, check these related SO question [26098009](http://stackoverflow.com/questions/26098009) and [29776725](http://stackoverflow.com/questions/29776725). Also, another tutorial that can help you is this [Google OAuth2 for C#](http://www.daimto.com/google-oauth2-csharp/#Stored_refresh-Token). – KENdi Nov 04 '16 at 09:00

1 Answers1

-1

This is the good info using:

var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
    string credPath = System.Environment.GetFolderPath(
    System.Environment.SpecialFolder.Personal);
    credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");

    credential = GoogleWebAuthorizationBroker.AuthorizeAsync
    (
        GoogleClientSecrets.Load(stream).Secrets,
        Scopes,
        "user",
        CancellationToken.None,
        new FileDataStore(credPath, true)
    ).Result;

    Console.WriteLine("Credential file saved to: " + credPath);
}
krlzlx
  • 5,752
  • 14
  • 47
  • 55