Coordinate API OAuth2 authentication with refresh token

330 views Asked by At

I am looking for a sample code to authenticate Coordinate API using OAuth2 with an existing refresh token. I am looking for something similar in the thread Google Coordinate OAuth2 with Service Account. I have tried that code snippet but I faced some issue due to the dll conflict. And from the nuget library it seems like the Google.Apis.Authentication.OAuth2 is deprecated and we should use Google.Apis.Authinstead.

So If somebody can provide a sample code which will work with Google.Apis.Auth that would be great.

Please help.

1

There are 1 answers

0
jineesh MG On BEST ANSWER

I am able to find a solution by trying different combination. Adding the sample code and I think it will help somebody looking for a similar solution.

        using Google.Apis.Auth.OAuth2;
        using Google.Apis.Coordinate.v1;
        using Google.Apis.Coordinate.v1.Data;
        using Google.Apis.Services;
        using Google.Apis.Util.Store;


        using (var stream = new FileStream(@"client_secret.json", FileMode.Open, FileAccess.Read))
        {
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
            new[] { CoordinateService.Scope.Coordinate },
            "user", CancellationToken.None,new FileDataStore(folder));
        }

        var service = new CoordinateService(new BaseClientService.Initializer()
        {
        HttpClientInitializer = credential,
        ApplicationName = "appname",
        });

        var list = await service.Location.List("teamid", "[email protected]", 2000).ExecuteAsync();

Hope this will help.

Thanks, MG