Google Drive Android API ConnectionResult错误

goo*_*ly2 5 android google-drive-api android-studio google-drive-android-api

我正在创建一个应用程序,我正在将Google Drive Android API集成到其中.我有一个主要活动,然后打开一个片段,导致谷歌驱动器.但是,当我尝试登录时(无论是什么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);
    }
}
Run Code Online (Sandbox Code Playgroud)

并从我使用的主要活动中调用它

Fragment fragment = FileSharingFragment.newInstance();
FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
Run Code Online (Sandbox Code Playgroud)

我不能为我的生活弄清楚为什么它不会让我登录.

小智 0

通过 Google Developers Console,转到 API & Auth -> Credentials 并检查包名称是否与您的应用程序包名称完全相同。