简体   繁体   中英

Google.Drive.Api Oauth 2 Credientials in Xamarin android application

I am trying to read a file from google drive using my xamarin android application using google.drive.api, the latter requests Google Oauth2 ID credentials for Android to be authorized to access Google drive.

The debugging stops here :

credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                new ClientSecrets
                {
                    ClientId = "My-Client-ID",
                    ClientSecret = null
                },
                Scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;

and raises and exception :

System.AggregateException: 'One or more errors occurred. (Failed to launch browser with "https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&response_type=code&client_id=MY-CLIENT-ID&redirect_uri=http%3A%2F%2F127.0.0.1%3A46401%2Fauthorize%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.readonly" for authorization. See inner exception for details.)'

Note : It worked fine when trying it on a Desktop console application using an Oauth ID for desktop app.

GoogleWebAuthorizationBroker.AuthorizeAsync was designed for use with installed applications only. The google .net client library does not support Xamarin auth. As can be seen on the README for the library.

在此处输入图像描述

You will not be able to use this library for authentication. Your going to have to code the authorization yourself. I have done it in the past for a client it is doable.

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