Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive Android API ConnectionResult Error

I'm making an app and I'm integrating the Google Drive Android API into it. I have a main activity then a fragment that opens that leads to google drive. However, when I try to sign in (it doesn't matter what gmail account, I've tried existing ones, creating new ones, whatever) I get ConnectionResult error code 17 SIGN_IN_FAILED. The app is authorized in the developer console and the Drive API is enabled. I don't know what else to do.

Here is the relevant code:

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);
    }
}

And to call it from the main activity I use

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

I cannot for the life of me figure out why it won't let me sign in.

like image 768
googlygoogly2 Avatar asked Nov 01 '22 06:11

googlygoogly2


2 Answers

You probably know by now that your Developers Console needs 3 things:

1/ SHA1 of yout APK
2/ your package name
3/ your email/product name in the Consent Screen

Assuming everything is OK there, here's the last-resort double-check I use often:
- open (unzip) your xxxx.APK using unzipper (like 7zip), find CERT.RSA.
- run 'keytool -printcert -file .........\CERT.RSA'
Go back to the console and compare the SHA1's again.

Good Luck

like image 132
seanpj Avatar answered Nov 12 '22 11:11

seanpj


It might seem obvious but if you've entered your fingerprint on the developer console and set up your API there and are still getting SIGN_IN_FAILED make sure you are actually using the signed APK!

It's too easy to run installDebug from Gradle and forget. I usually set it up and go through the menus (Build > Generate Signed APK...) in Android Studio when I'm working with Google SDK's

like image 39
Nick Cardoso Avatar answered Nov 12 '22 13:11

Nick Cardoso