这是谷歌加
你需要在你的项目中添加一些权限答库。
public class MainActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.OnConnectionFailedListener {
private SignInButton signInButton;
private GoogleSignInOptions gso;
private GoogleApiClient mGoogleApiClient;
private int RC_SIGN_IN = 100;
private TextView textViewName;
private TextView textViewEmail;
private NetworkImageView profilePhoto;
private ImageLoader imageLoader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewName = (TextView) findViewById(R.id.textViewName);
textViewEmail = (TextView) findViewById(R.id.textViewEmail);
// profilePhoto = (NetworkImageView) findViewById(R.id.profileImage);
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
signInButton = (SignInButton) findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_WIDE);
signInButton.setScopes(gso.getScopeArray());
mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */).
addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
signInButton.setOnClickListener(this);
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
public void sign_out(View view) {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
Toast.makeText(getApplicationContext(), "SIGN OUT SUCESSFULLY", Toast.LENGTH_LONG).show();
textViewName.setText("");
textViewEmail.setText("");
}
});
// Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
// new ResultCallback<Status>() {
// @Override
// public void onResult(Status status) {
// // ...
// }
// });
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
private void handleSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
GoogleSignInAccount acct = result.getSignInAccount();
textViewName.setText(acct.getDisplayName());
textViewEmail.setText(acct.getEmail());
// Toast.makeText(this,acct.get)
//Initializing image loader
// imageLoader = CustomVolleyRequest.getInstance(this.getApplicationContext())
// .getImageLoader();
//
// imageLoader.get(acct.getPhotoUrl().toString(),
// ImageLoader.getImageListener(profilePhoto,
// R.mipmap.ic_launcher,
// R.mipmap.ic_launcher));
//
// //Loading image
// profilePhoto.setImageUrl(acct.getPhotoUrl().toString(), imageLoader);
} else {
Toast.makeText(this, "Login Failed", Toast.LENGTH_LONG).show();
}
}
@Override
public void onClick(View v) {
if (v == signInButton) {
signIn();
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
您的API发送令牌上的反应时,你有身份验证的帐户,如果是这样的话,如果有人试图与Facebook登录或谷歌首先是检查与DB相关的电子邮件,如果没有的话转发他们注册活动创建一个帐户..稍后链接他们的帐户,并且如果他们尝试使用fb或谷歌登录下次...它将在数据库中,因此通过提供令牌将其重定向到主页 –