简体   繁体   中英

Coordinate API OAuth2 authentication with refresh token

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.Auth instead.

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

Please help.

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", "team@mailid.com", 2000).ExecuteAsync();

Hope this will help.

Thanks, MG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM