I have to implement signin with facebook and google plus in my android application.Successfully implemented facebook as like the below image.
But when i implement sign in with Google plus it shows like Google plus image link
Please someone help me to implement the same like the Facebook Login for sign in with Google plus in android. So that user can enter whatever gmail account he prefer to sign in to Google.
I'm using SocialAuth library, which supports many social networks, including Facebook
and Google+
.
Note: Can provide code examples how to login in corresponding social networks using this library (Facebook, Google+) later, if needed.
Update:
1) client id's are stored in oauth_consumer.properties
file (put it in assets
folder)
#facebook
graph.facebook.com.consumer_key = YOUR_KEY
graph.facebook.com.consumer_secret = YOUR_SECRET
#Google Plus
googleapis.com.consumer_key=YOUR_KEY.apps.googleusercontent.com
googleapis.com.consumer_secret=YOUR_SECRET
2) Google+
requires redirect url. Specify redirect url in google console of the project and add it in SocialAdapter
during initialization.
...
socialAuthAdapter = new SocialAuthAdapter(new ResponseListener(), null);
setAuthProviders();
...
private void setAuthProviders() {
socialAuthAdapter.addProvider(SocialAuthAdapter.Provider.FACEBOOK, R.drawable.facbook);
socialAuthAdapter.addProvider(SocialAuthAdapter.Provider.GOOGLEPLUS, R.drawable.google);
socialAuthAdapter.addCallBack(SocialAuthAdapter.Provider.GOOGLEPLUS, GOOGLE_PLUS_CALLBACK_URL);
//urn:ietf:wg:oauth:2.0:oob - if you set this url, than accessToken received from social network should be handled manually (web page (in WebView) with login response from Google+ will contain in header or in response link accessToken, and you will get it manually by parsing that links). not the best way.
socialAuthAdapter.enable(social);
}
3) You will get accessToken in ResponseListener
when login flow will be finished:
private class ResponseListener implements DialogListener {
@Override
public void onComplete(Bundle bundle) {
final String providerName = bundle.getString(SocialAuthAdapter.PROVIDER);
SocialNetwork network = SocialNetwork.valueOf(providerName);
String accessToken = socialAuthAdapter.getCurrentProvider().getAccessGrant().getKey();
}
@Override
public void onError(final SocialAuthError socialAuthError) {
}
@Override
public void onCancel() {
}
@Override
public void onBack() {
}
}
You can read more about redirect url here, in "Forming the URL for an authentication request" section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With