I use the SocialAuth library, which supports many social networks, including Facebook and Google+ .
Note. If necessary, you can give examples of the code to enter the relevant social networks using this library (Facebook, Google+) later.
Update:
1) the client identifier is stored in the oauth_consumer.properties file (put it in the assets folder)
#facebook graph.facebook.com.consumer_key = YOUR_KEY graph.facebook.com.consumer_secret = YOUR_SECRET
2) Google+ is required to redirect the URL. Specify the redirect URL in the project’s Google console and add it to the 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 receive accessToken in ResponseListener when login is completed:
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() { } }
Read more about URL redirection here in the section "Generating a URL for an authentication request."
source share