I've been following this tutorial. http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/
But when I'm tested the app through the real device, When I click on the Sign in button, a toast is appeared saying "An internal error has occurred"
Could you please help me with this. Thanks in advance.
Usually 'Internal error' shows up if one of the following is wrong:
In Google's Developer console website :
Inside the Project:
Credentials
Consent Screen
If all these are correct, it should work automatically....
Try below code:
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private static final int REQUEST_CODE_SHARE = 1000;
private PlusClient mPlusClient;
private PlusClient.Builder mPlusClientBuilder;
private PlusShare.Builder mPlusShareBuilder;
// In your onCreate()
mPlusClientBuilder = new Builder(this, this, this);
mPlusClientBuilder.setScopes(Scopes.PLUS_LOGIN, Scopes.PROFILE);
mPlusClient = mPlusClientBuilder.build();
mPlusClient.connect();
// Overrides methods
@Override
public void onConnectionFailed(ConnectionResult result) {
if (result.hasResolution()) {
// The user clicked the sign-in button already. Start to resolve
// connection errors. Wait until onConnected() to dismiss the
// connection dialog.
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.disconnect();
mPlusClient.connect();
}
}
}
@Override
public void onConnected(Bundle arg0) {
String accountName = mPlusClient.getAccountName();
btnSignIn.setText(getString(R.string.signout));
textUserName.setText(accountName);
}
// Signin Click event
btnSignIn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (!mPlusClient.isConnected() && btnSignIn.getText().equals(getString(R.string.signin))) {
mPlusClient.connect();
} else if (mPlusClient.isConnected() && btnSignIn.getText().equals(getString(R.string.signout))) {
mPlusClient.clearDefaultAccount();
mPlusClient.disconnect();
btnSignIn.setText(getString(R.string.signin));
textUserName.setText("");
txtLoginAs.setVisibility(View.GONE);
}
}
});
//onActivityResult
@Override
protected void onActivityResult(int requestCode, int responseCode, Intent data) {
super.onActivityResult(requestCode, responseCode, data);
if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
mPlusClient.disconnect();
mPlusClient.connect();
} else if (requestCode == REQUEST_CODE_SHARE && responseCode == RESULT_OK) {
finish();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.