我认为应用程序中 google+ 登录集成的基本步骤您都知道。以下是其余步骤
第一步——
在 oncreate 中
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
第 2 步——
在登录按钮点击监听器调用这个----
private void LoginGoogle(){
int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
if (errorCode != ConnectionResult.SUCCESS) {
GooglePlayServicesUtil.getErrorDialog(errorCode, this, 0).show();
}
else{
//perform login
if (!mGoogleApiClient.isConnecting()) {
mSignInClicked = true;
mGoogleApiClient.connect();
}
}
}
第 3 步----
在 onActivityresult 中
if (requestCode == RC_SIGN_IN) {
if (resultCode != RESULT_OK) {
mSignInClicked = false;
}
mIntentInProgress = false;
if (!mGoogleApiClient.isConnected()) {
mGoogleApiClient.reconnect();
}
}
step 4-----
@Override
public void onConnectionFailed(ConnectionResult result) {
// TODO Auto-generated method stub
if(!mIntentInProgress){
if ( mSignInClicked && result.hasResolution()) {
// The user has already clicked 'sign-in' so we attempt to resolve all
// errors until the user is signed in, or they cancel.
try {
result.startResolutionForResult(this, RC_SIGN_IN);
mIntentInProgress = true;
} 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();
}
}
}
}
@Override
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
mSignInClicked = false;
getProfileInformation();
}
@Override
public void onConnectionSuspended(int arg0) {
// TODO Auto-generated method stub
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
第五步-----
private void getProfileInformation(){
try {
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
String id=currentPerson.getId();
String personName = currentPerson.getDisplayName();
String personPhoto = currentPerson.getImage().getUrl();
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
String profilePic=personPhoto.substring(0,
personPhoto.length() - 2)
+ ProfilePicSize;
Log.e("GOOGLE", id);
Log.e("GOOGLE", personName);
Log.e("GOOGLE", profilePic);
Log.e("GOOGLE",email);
}
} catch (Exception e) {
e.printStackTrace();
}
}