Android:Google云端硬盘onActivityResult()获得resultCode 0(RESULT_CANCELED) [英] Android: Google Drive onActivityResult() getting resultCode 0 (RESULT_CANCELED)

查看:158
本文介绍了Android:Google云端硬盘onActivityResult()获得resultCode 0(RESULT_CANCELED)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找Google文档和示例代码以及Stack Overflow来寻求解决方案,尽管我看到许多人遇到相同的症状,但我没有发现任何对我的情况有帮助的东西

I've been scouring the Google documentation and sample code and Stack Overflow for a solution to this, and while I've seen a number of people running into the same symptoms I haven't found anything that helps in my particular case.

基本上,我正在尝试为Google Drive REST API做一个身份验证工作流,虽然我到达了Google帐户选择页面,但当它返回到我的通话活动时,我总是会看到RESULT_CANCELED的结果(即0)而不是RESULT_OK(即-1),无论选择了哪个帐户.

Basically I'm trying to do an auth workflow for the Google Drive REST API, and while I get as far as the Google account selection page, when it returns to my calling activity, I'm always seeing a result of RESULT_CANCELED (i.e., 0) instead of RESULT_OK (i.e., -1), no matter what account is selected.

我已检查以确保在Google开发人员控制台上正确设置了凭据-并且它们以前通过现已失效的CloudRail库进行身份验证. (据我所知,现在通过Google登录,您提供任何客户端ID,等等:当与您的软件包名称匹配时,这些操作都将在Google端处理.)

I've checked to make sure that the credentials are set up correctly on the Google developer console — and they were working previously with authentication via the now-defunct CloudRail library. (As far as I can tell, now with Google Sign-In you don't provide any client id, etc.: that's all handled on Google's end when it matches your package name.)

这是我要求认证的电话:

Here is my call for authentication:

    GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope(DriveScopes.DRIVE))
            .build();
    mSignInClient = GoogleSignIn.getClient(activity, signInOptions);

这是活动的onActivityResult():

@Override
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
    switch (requestCode) {
        case REQUEST_GOOGLE_SIGN_IN:
            if (resultCode == Activity.RESULT_OK && resultData != null) {
                /*** NEVER GET HERE ***/
                handleSignInResult(this, resultData);
            }
            else {
                /*** ALWAYS GET HERE ***/
                Log.e(TAG, String.format("Unable to complete Google sign-in (resultCode: %d)", resultCode));
            }
        }
        break;
    }
    super.onActivityResult(requestCode, resultCode, resultData);
}

我以为这是我做某件事显然是愚蠢和错误的情况-并希望只是输入问题可以帮助我弄清楚它是什么,但这还没有发生.

I'm assuming that this is a case of me doing something obviously dumb and wrong — and was hoping that just typing out the question would help me figure out what it is, but that hasn't happened yet.

推荐答案

正如我所料,我做错了相对简单的事情.因此,对于遇到相同问题并在寻找解决方案时跨过我的身体的任何人,这就是我发现的东西:

As I expected, it was something relatively simple that I was doing wrong. So for anyone having the same issue and stepping over my body while searching for a solution, here's what I found:

虽然我 did 正确设置了Google开发人员控制台中的凭据,并按照文档的指示从mykeystore.keystore中生成了我的软件包名称和SHA1,但我错过的是Android Studio 默认情况下不使用mykeystore.keystore对调试版本进行签名.相反,它使用自己提供的debug.keystore.

While I did have the credentials in the Google developer console set up correctly, with my package name and SHA1 generated, as directed by the documentation, from mykeystore.keystore, what I missed was that Android Studio doesn't sign debug builds with mykeystore.keystore by default. Instead it uses its own provided debug.keystore.

因此,要做的是使用您的包名称和来自Android Studio的debug.keystore而非自己的SHA1的SHA1创建一个新的OAuth客户端ID. (您可以在系统上查找debug.keystore,或运行Gradle"signingReport"任务并从那里获取它.)

So the thing to do is to create a new OAuth client ID with your package name and the SHA1 from Android Studio's debug.keystore instead of one's own. (You can either hunt down debug.keystore on your system, or run the Gradle "signingReport" task and get it from there.)

希望能帮助到某人.

这篇关于Android:Google云端硬盘onActivityResult()获得resultCode 0(RESULT_CANCELED)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆