我正在使用Google+登录我的应用程序。当我点击Google按钮时,会调用OnConnect()方法,但是我从OnConnect()方法中检索有关Google的一些信息,但“Plus.PeopleApi.getCurrentPerson(mGoogleApiClient)”方法返回null值。请帮助我。
// Google API Services CallBack Method
private boolean mSignInClicked;
private ConnectionResult mConnectionResult;
private void loginWithGoogle() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
mGoogleApiClient.connect();
}
@Override
public void onConnected(Bundle arg0) {
mSignInClicked = false;
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi
.getCurrentPerson(mGoogleApiClient);
String personName = currentPerson.getDisplayName();
Log.i("personName", personName);
Image personPhoto = currentPerson.getImage();
String photoUrl = personPhoto.getUrl();
Log.i("photoUrl", photoUrl);
String personGooglePlusProfile = currentPerson.getUrl();
Log.i("personGooglePlusProfile", personGooglePlusProfile);
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
Log.i("email", email);
boolean hasBirthday = currentPerson.hasBirthday();
Log.i("hasBirthday", "" + hasBirthday);
String birthday = currentPerson.getBirthday();
Log.i("birthday", "" + birthday);
boolean hasAbout = currentPerson.hasAboutMe();
Log.i("hasAbout", "" + hasAbout);
String about = currentPerson.getAboutMe();
Log.i("about", "" + about);
String Id = currentPerson.getId();
Log.i("Id", Id);
int gender = currentPerson.getGender();
Log.i("gender", "" + gender);
boolean hasLocation = currentPerson.hasCurrentLocation();
Log.i("hasLocation", "" + hasLocation);
String location = currentPerson.getCurrentLocation();
Log.i("location", "" + location);
AgeRange agerange = currentPerson.getAgeRange();
if (agerange != null)
Log.i("agerange", "" + agerange.toString());
Name name = currentPerson.getName();
Log.i("getFamilyName", name.getFamilyName());
btnGoogle = true;
new ApiCall().execute(url);
if (mGoogleApiClient.isConnected()) {
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
mGoogleApiClient.disconnect();
}
} else {
Log.i("personName", "getCurrentPerson(mGoogleApiClient) is null");
}
}
@Override
public void onConnectionSuspended(int arg0) {
mGoogleApiClient.connect();
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (!mIntentInProgress) {
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();
}
}
}
public void resolveSignInError() {
if (mConnectionResult.hasResolution()) {
try {
mIntentInProgress = true;
mConnectionResult.startResolutionForResult(this, RC_SIGN_IN);
} catch (SendIntentException e) {
// The intent was canceled before it was sent. Return to the
// default
// state and attempt to connect to get an updated
// ConnectionResult.
mIntentInProgress = false;
mGoogleApiClient.connect();
}
}
}
Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this);
? - SweetWisher ツ