6

I am using the code as shown in this https://developers.google.com/drive/android/auth#connecting_and_authorizing_the_google_drive_android_api

In my app I click to connect to Drive, but it results in this line being executed

 connectionResult.startResolutionForResult(this, 1);

As the connection fails.

Then it opens an account menu for me to choose an account. When I click it then the dialog dismisses and I still can not connect to Google Drive because everytime the result code is 0

protected void onActivityResult(final int requestCode, final int resultCode,      final Intent data) {
    switch (requestCode) {
        case 1:
            if (resultCode == RESULT_OK) {
                mGoogleApiClient.connect();
           }
            break;
    }
}

I would assume the code is correct, but does anyone know what I need to do to prevent is canceling? I believe I set up my credentials correctly for the OA Auth

BMK
  • 63
  • 4

1 Answers1

0

I tried using the Drive demo code by Google here and I was able to run the android sample. Check their implementation of authentication and try to compare it with yours. Here's the relevant part:

@Override
    protected void onResume() {
        super.onResume();
        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(Drive.API)
                    .addScope(Drive.SCOPE_FILE)
                    .addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();
        }
        mGoogleApiClient.connect();
    }

    /**
     * Handles resolution callbacks.
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_RESOLUTION && resultCode == RESULT_OK) {
            mGoogleApiClient.connect();
        }
    }

I was able to login successfully and tried out some of the features. If you're going to use this sample, don't forget to setup your Credentials like Oauth CliendID and indicate the correct package name indicated in the Getting Started guide.

Here's what it looks like:

enter image description here

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56