问题
I am new to android development. I am integrating google plus login into my App, I am little bit confusing that the Singing in prompt of google is occurring repeatedly. I can't understand why, is anything wrong with me?
I am following Google Developer Site to make this thing. I tested the app using multiple google account but 2 of them are works fine but rest of the account did not.
回答1:
Have you tried:
How do I debug my Google+ integration?
By enabling logging, you can diagnose network issues when working with the Google APIs.
To enable logging, run the following command:
adb shell setprop log.tag.GooglePlusPlatform VERBOSE
To disable logging, run the following command:
adb shell setprop log.tag.GooglePlusPlatform ""
Permission which you have to add:
To access Google+ APIs:
<uses-permission android:name="android.permission.INTERNET" />
To retrieve the account name (email) as part of sign-in:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
To retrieve OAuth 2.0 tokens or invalidate tokens to disconnect a user. This disconnect option is required to comply with the Google+ Sign-In developer policies:
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
See, if that helps.
回答2:
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
onCreate(Bundle bundle){
mGoogleApiClient = new GoogleApiClient.Builder(YourActivity.this)
.addConnectionCallbacks(YourActivity.this)
.addOnConnectionFailedListener(YourActivity.this).addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
}
btn_gpluslogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signInWithGplus();
}
});
private void signInWithGplus() {
if (!mGoogleApiClient.isConnecting()) {
mSignInClicked = true;
resolveSignInError();
}
}
private void resolveSignInError() {
if (mConnectionResult.hasResolution()) {
try {
mIntentInProgress = true;
mConnectionResult.startResolutionForResult(this, RC_SIGN_IN);
} catch (IntentSender.SendIntentException e) {
mIntentInProgress = false;
mGoogleApiClient.connect();
}
}
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (!result.hasResolution()) {
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this,
0).show();
return;
}
if (!mIntentInProgress) {
// Store the ConnectionResult for later usage
mConnectionResult = result;
if (mSignInClicked) {
// The user has already clicked 'sign-in' so we attempt to
// resolve all
// errors until the user is signed in, or they cancel.
resolveSignInError();
}
}
}
@Override
public void onConnected(Bundle arg0) {
mSignInClicked = false;
Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();
// Get user's information
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
boolean isSignedUp = pref.getBoolean("isSignedUp", false);
if (!isSignedUp)
getGProfileInformation();
// Update the UI after signin
}
private void updateUI(boolean isSignedIn) {
if (isSignedIn) {
getGProfileInformation();
} else {
btn_gpluslogin.setVisibility(View.VISIBLE);
}
}
/**
* Fetching user's information name, email, profile pic
*/
private void getGProfileInformation() {
try {
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi
.getCurrentPerson(mGoogleApiClient);
Log.d("Google Info", currentPerson.toString());
String personName = currentPerson.getDisplayName();
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
} else {
Toast.makeText(getApplicationContext(),
"Person information is null", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
回答3:
Since you did not provided any code, let me guess. If you say you have problems with certain accounts and others not, it seems to me these problematic accounts have not authorized your app. Please check (while logged in a browser) this configuration:
https://security.google.com/settings/security/permissions?pli=1
Or this?
https://plus.google.com/u/0/apps
And look for your app in the list. Maybe your permissions were denied or something. Perhaps you just need to grant them again, reset and try again.
回答4:
Here is what I bet is happening.
In onConnectionFailed you are starting the resolution from the connectionResult. This then launches the Activity to resolve the failure and should return the result to onActivityResult. However you need to make sure not to get into a resolution loop.
So in onConnectionFailed, do this:
private boolean mIsResolving = false;
// ...
public void onConnectionFailed(ConnectionResult connectionResult) {
if (connectionResult.hasResolution() && !mIsResolving) {
mIsResolving = true;
connectionResult.startResolutionForResult(this, RC_SIGN_IN);
}
}
Then in onActivityResult do this:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
if (resultCode == RESULT_OK) {
mIsResolving = false;
mGoogleApitClient.connect();
} else {
// ...
}
}
}
来源:https://stackoverflow.com/questions/28104850/google-plus-login-android-singing-in-prompt-is-repeatedly-occure-while-login