首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用谷歌注册v3

使用谷歌注册v3
EN

Stack Overflow用户
提问于 2020-06-08 17:25:42
回答 1查看 243关注 0票数 0

我想在我的Android应用程序中添加一个在用户GoogleDrive上存储文件的功能。应用程序使用Xamarin.Android。如Google文档所述:(https://developers.google.com/drive/api/v3/about-auth#AboutAuthorization)

关于授权协议的

,您的应用程序必须使用OAuth 2.0来授权请求。不支持其他授权协议。如果您的应用程序使用Google登录,授权的某些方面将为您处理。

Google In是可能的,而且应该更容易。但是,我找到的所有Google SingIn示例都以获取用户属性(如电子邮件或姓氏)为结束,但我无法找到如何将接收到的用户属性用于Google或任何其他API授权。例如,来自Google站点:

代码语言:javascript
复制
    GoogleSignInAccount account = completedTask.getResult(ApiException.class);

    // Signed in successfully, show authenticated UI.
    updateUI(account);

或者在下面的C#示例中:

代码语言:javascript
复制
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
    base.OnActivityResult(requestCode, resultCode, data);

    if(requestCode == SING_IN_ACTIVITY_RESULT)
    {
        GoogleSignInResult res = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
        if(res.IsSuccess)
        {
            GoogleSignInAccount googleAccount = res.SignInAccount;
        }
    }
}

而Drive服务需要UserCredential对象,这是OAuth2过程的结果:

代码语言:javascript
复制
     { //...
        UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.Load(stream).Secrets,
            Scopes,
            "user",
            CancellationToken.None,
            new FileDataStore(credPath, true)).Result;
    }

    // Create Drive API service.
    var service = new DriveService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = ApplicationName,
    });

如何将GoogleSignInAccount转换为UserCredential?

EN

回答 1

Stack Overflow用户

发布于 2020-06-08 17:32:05

GoogleSingIn只需登录,您就不能将结果转换为UserCredential,然后使用谷歌驱动器.

解决方案将是寻找特定的google驱动API。

https://developers.google.com/drive

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62267834

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档