Google Drive Android API连接结果错误

Google Drive Android API连接结果错误,android,android-studio,google-drive-api,google-drive-android-api,Android,Android Studio,Google Drive Api,Google Drive Android Api,我正在制作一个应用程序,并将Google Drive Android API集成到其中。我有一个主要的活动,然后是一个片段,它打开了谷歌驱动器。然而,当我尝试登录时(不管是哪个gmail帐户,我已经尝试了现有帐户,创建了新帐户,无论什么),我得到了ConnectionResult错误代码17登录失败。应用程序在开发人员控制台中获得授权,并且驱动器API已启用。我不知道还能做什么 以下是相关代码: public class FileSharingFragment extends Fragment

我正在制作一个应用程序,并将Google Drive Android API集成到其中。我有一个主要的活动,然后是一个片段,它打开了谷歌驱动器。然而,当我尝试登录时(不管是哪个gmail帐户,我已经尝试了现有帐户,创建了新帐户,无论什么),我得到了ConnectionResult错误代码17登录失败。应用程序在开发人员控制台中获得授权,并且驱动器API已启用。我不知道还能做什么

以下是相关代码:

public class FileSharingFragment extends Fragment implements
    GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
        }
        mGoogleApiClient.connect();
    }

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_file_sharing, container, false);
    users = (TextView) rootView.findViewById(R.id.users);
    getActivity().setTitle("Files");
    return rootView;
}

    @Override
public void onActivityResult(int requestCode, int resultCode,
                                Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_RESOLUTION && resultCode == Activity.RESULT_OK) {
        mGoogleApiClient.connect();
    }
}

@Override
public void onConnectionFailed(ConnectionResult result) {
    Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
    if (!result.hasResolution()) {
        // show the localized error dialog.
        GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), getActivity(), 0).show();
        Log.i("file sharing fragment", "error code " + result.getErrorCode());
        return;
    }
    try {
        result.startResolutionForResult(getActivity(), REQUEST_CODE_RESOLUTION);
    } catch (IntentSender.SendIntentException e) {
        Log.e(TAG, "Exception while starting resolution activity", e);
    }
}
从我使用的主要活动中调用它

Fragment fragment = FileSharingFragment.newInstance();
FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

我一辈子都搞不明白为什么它不让我登录。

在Google开发者控制台上,转到API&Auth->Credentials,检查包名是否与您的应用程序包名完全相同。

您现在可能知道您需要3件事:

yout APK的1/SHA1
2/您的包裹名称
3/同意屏幕中的电子邮件/产品名称

假设那里一切正常,下面是我经常使用的最后一种方法:双重检查:
-使用解压(如7zip)打开(解压)您的xxxx.APK,找到CERT.RSA。
-运行“keytool-printcert-file………\CERT.RSA”
返回控制台,再次比较SHA1


祝你好运

这似乎很明显,但如果你在开发者控制台上输入了指纹并在那里设置了API,并且仍然获得了
登录失败
请确保你实际使用的是已签名的APK


从Gradle运行
installDebug
并忘记它太容易了。当我使用Google SDK时,我通常会在Android Studio中设置并浏览菜单(Build>Generate Signed APK…),确保生成的是OAuth 2.0客户端ID,而不是普通的API密钥


-您的应用程序必须发送OAuth 2.0令牌以及访问私有用户数据的任何请求

尝试卸载应用程序并启动整个调试过程(如果您使用的是debug.keystore。

是否正确地遵循了给定的所有步骤?通过.BTW,如果您使用的是Android Studio,您可以尝试此方法,具体地说,通过一步一步来看看它是否能帮到您。)