android - Google Drive Android API ConnectionResult 错误

标签 android android-studio google-drive-api google-drive-android-api

我正在制作一个应用程序并将 Google Drive Android API 集成到其中。我有一个主要 Activity ,然后是一个 fragment ,该 fragment 打开导致谷歌驱动器。但是,当我尝试登录时(不管是什么 gmail 帐户,我都尝试过现有帐户、创建新帐户等等),我收到 ConnectionResult 错误代码 17 SIGN_IN_FAILED。该应用程序已在开发者控制台中获得授权并启用了 Drive 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);
    }
}

并从我使用的主要 Activity 中调用它

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

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

最佳答案

您现在可能知道您的 Developers Console需要三样东西:

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

假设一切正常,这是我经常使用的最后手段复查:
- 使用解压器(如 7zip)打开(解压)您的 xxxx.APK,找到 CERT.RSA。
- 运行 'keytool -printcert -file .........\CERT.RSA'
返回控制台并再次比较 SHA1。

祝你好运

关于android - Google Drive Android API ConnectionResult 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29689832/

相关文章:

java - Google Drive Java API V3 删除自定义属性

google-api - Google Drive API - 查询每个共享文件(与我共享或我与其他人共享)

android - TabLayout Android 颜色错误

java - 将 ZbarScanner 与安卓应用集成

java - 更改 Android 应用程序代码中的按钮文本

java - 无法使用我的 POJO 解析构造函数 ArrayAdapter

Android 相对布局选择器

android - Robotium 主页按钮并恢复到应用程序

android - 如何将系统库添加到 Android Studio?

google-drive-api - Google云端硬盘MIME类型列表?