简体   繁体   English

Xamarin android 应用程序中的 Google.Drive.Api Oauth 2 凭据

[英]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.我正在尝试使用我的 xamarin android 应用程序使用 google.drive.api 从 google 驱动器读取文件,后者请求 Android 的 Google Oauth2 ID 凭据被授权访问 Google 驱动器。

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. System.AggregateException: '发生一个或多个错误。 (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.)' (无法使用“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" 用于授权。有关详细信息,请参阅内部异常。)'

Note : It worked fine when trying it on a Desktop console application using an Oauth ID for desktop app.注意:在使用桌面应用程序的 Oauth ID 的桌面控制台应用程序上尝试它时效果很好。

GoogleWebAuthorizationBroker.AuthorizeAsync was designed for use with installed applications only. GoogleWebAuthorizationBroker.AuthorizeAsync旨在仅用于已安装的应用程序。 The google .net client library does not support Xamarin auth. google .net 客户端库不支持 Xamarin 身份验证。 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.我过去曾为客户做过这件事,这是可行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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