Posts Android implement G/FB/TW login via socialauth-android library
Post
Cancel

Android implement G/FB/TW login via socialauth-android library

Start points (requires go0gle plays services library) using Google+ : https://developers.google.com/+/mobile/android/sign-in

This method described (dont require go0gle plays services, but needs a 3rd party JARs (total filesize = 275kb)) :

ok,so we are again at Google Cloud Console (and we created a project) https://cloud.google.com/console we have to create n OAuth 2.0 client ID

first enable from API menu the option Google+ API

then goto Registered apps > select Native (I didnt try with other choices)

this will result  a Client Secret

download the socialauth-android http://code.google.com/p/socialauth-android/

you must include the 2jars and oauth_consumer.properties file into your project

edit oauth_consumer.properties file write there the Client Secret (btw offers login to all social webistes, google is just 1 of them)

1
2
 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
	SocialAuthAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);

			// Add it to Library
			adapter = new SocialAuthAdapter(new ResponseListener());

			// Add providers
			adapter.addProvider(Provider.FACEBOOK, R.drawable.facebook);
			adapter.addProvider(Provider.TWITTER, R.drawable.twitter);
			adapter.addProvider(Provider.TWITTER, R.drawable.google);

			// Providers require setting user call Back url
			adapter.addCallBack(Provider.TWITTER, "http://socialauth.in/socialauthdemo/socialAuthSuccessAction.do");

	}

	public void btnFB_Click(View view) {
		adapter.authorize(LoginActivity.this, Provider.FACEBOOK);
	}

	public void btnTW_Click(View view) {
		adapter.authorize(LoginActivity.this, Provider.TWITTER);
	}

	public void btnGOOGLE_Click(View view) {
		adapter.authorize(LoginActivity.this, Provider.GOOGLE);
		//alternatively for Google+ you use Provider.GOOGLEPLUS
	}

	//socialauth-android listener
	private final class ResponseListener implements DialogListener {
		@Override
		public void onComplete(Bundle values) {
			String providerName = values.getString(SocialAuthAdapter.PROVIDER);
			String token = adapter.getCurrentProvider().getAccessGrant().getKey();

			if (adapter != null)
				if (adapter.getUserProfile() != null) {
					userEmail = adapter.getUserProfile().getEmail();
					userDisplayName = adapter.getUserProfile().getDisplayName();
					userSocialID = adapter.getUserProfile().getValidatedId();

					if (providerName.equalsIgnoreCase("facebook")) {
						if (token != null && userEmail != null && userSocialID != null) {
							//success login
							});
						} else
							General.mes(LoginActivity.this, "Unable to authenticate user");
					} else if (providerName.equalsIgnoreCase("google")) {

						if (token != null && userEmail != null && userSocialID != null) {
							//success login
							});
						} else
							General.mes(LoginActivity.this, "Unable to authenticate user");

					} else if (providerName.equalsIgnoreCase("twitter")) {
					//pipiscrew
					}
				}
		}

		@Override
		public void onError(SocialAuthError error) {
			Log.d("PipisCrew", "Authentication Error: " + error.getMessage());
		}

		@Override
		public void onCancel() {
			Log.d("PipisCrew", "Authentication Cancelled");
		}

		@Override
		public void onBack() {
			Log.d("PipisCrew", "Dialog Closed by pressing Back Key");
		}

	}

origin - http://www.pipiscrew.com/?p=592 android-implement-google-login-via-socialauth-android-library

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags