Login effortlessly with different social networks like Facebook, Twitter or Google Plus

Overview

Android Arsenal jCenter

EasyLogin

Easy Login in your app with different social networks. Currently supported:

  • Facebook
  • Google Plus
  • Twitter

Global Configuration

To be able to use one of the social network connections you need to create an EasyLogin instance:

EasyLogin.initialize();
EasyLogin easyLogin = EasyLogin.getInstance();

Also make sure to call through to EasyLogin in onActivityResult() of your Activity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  easyLogin.onActivityResult(requestCode, resultCode, data);
}

Afterwards you can connect to the social networks one by one.

Facebook Connection

To connect to facebook you need to do the following:

  • First of all you need to init a list of permissions you want to take:
    List<String> fbScope = Arrays.asList("public_profile", "email");
    
  • Add the facebook social network:
    easyLogin.addSocialNetwork(new FacebookNetwork(this, fbScope));
    
  • Add the Facebook LoginButton and the listeners:
    facebook = (FacebookNetwork) easyLogin.getSocialNetwork(SocialNetwork.Network.FACEBOOK);
    
    LoginButton loginButton = (LoginButton) findViewById(R.id.facebook_login_button);
    // Call this method if you are using the LoginButton provided by facebook
    // It can handle its own state
    facebook.requestLogin(loginButton, this);
    
  • In the next step you will get an onSuccess() or onError() callback. The easiest solution is to implement the OnLoginCompleteListenerin your activity and handle all the connections there.

You also need to make sure to add the Facebook ApplicationId in your manifest:

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

If an email permission is requested, the library also does a /me request on the facebook graph api to try to fetch the email.

Note that it is still not guaranteed that you will get an email because the user might not have a valid / verified email or signed up with a telephone number. So I would advise to use the userId for figuring out the user identity.

Twitter Connection

One gotcha of using the Twitter Social connection is to create the TwitterNetwork before calling to setContentView() as Twitter would complain otherwise.

// Initialization needs to happen before setContentView() if using the LoginButton!
easyLogin.addSocialNetwork(new TwitterNetwork(this, twitterKey, twitterSecret));

setContentView(R.layout.activity_main);

twitter = (TwitterNetwork) easyLogin.getSocialNetwork(SocialNetwork.Network.TWITTER);
twitterButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
twitter.requestLogin(twitterButton, this);

If you also want to request an email from the Twitter use, use twitter.setAdditionalEmailRequest(true); Make sure that your app has the 'Request email addresses from users' checkbox checked in the Twitter app permission settings.

Note that it is still not guaranteed that you will get an email because the user might have signed up with a telephone number. So I would advise to use the userId for figuring out the user identity.

Google Plus Connection

easyLogin.addSocialNetwork(new GooglePlusNetwork(this));
gPlusNetwork = (GooglePlusNetwork) easyLogin.getSocialNetwork(SocialNetwork.Network.GOOGLE_PLUS);

gPlusButton = (SignInButton) findViewById(R.id.gplus_sign_in_button);
gPlusButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (!gPlusNetwork.isConnected()) {
            gPlusNetwork.requestLogin(MainActivity.this);
        }
    }
});

You can pass a reference to the SignInButton to the SocialNetwork by calling gPlusNetwork.setSignInButton(gPlusButton);. This will make sure to disable and enable the button on connection state changes. Unfortunately the state is not handled automatically inside the Button like the facebook button does.

As the state is not handled by the SignInButton you may need to call silentSignIn() in your onStart() to be logged in again. You will get a callback. For more info check the sample project. If you call silentSignIn() make sure to set a listener before.

You also need to include a valid google-services.json file in your project to be able to use G+: For more information you can consult the official docs.

Callbacks

 public class MainActivity extends AppCompatActivity implements OnLoginCompleteListener {
 
 [...]
 
 @Override
 public void onLoginSuccess(SocialNetwork.Network network) {
     // You can check the network by e.g.: if (network == SocialNetwork.Network.FACEBOOK) 
     AccessToken token = network.getAccessToken();
     Log.d("MAIN", "Login successful: " + token.getToken());
 }
 
 @Override
 public void onError(SocialNetwork.Network socialNetwork, String errorMessage) {
     Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_SHORT).show();
 }

Download

The library is available through jcenter().

After that you can easily include the library in your app build.gradle:

dependencies {
	        implementation 'com.maksim88:EasyLogin:{latest-version}'
	}

The builds are also available via jitpack.io.

License

Licensed under the MIT license. See LICENSE.

Comments
  • Google Plus login not work

    Google Plus login not work

    Hi,

    When I click on login button on Google plus nothing happen. Do you know what is wrong

    public class PageLoginFragment extends Fragment implements OnLoginCompleteListener {
    
        private View view;
    
        private EasyLogin mEasyLogin;
        ArrayList<String> fbScope;
        private LoginButton loginButton;
        private SignInButton gPlusButton;
        FacebookNetwork facebook;
        GooglePlusNetwork gPlusNetwork;
    
    
    
        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            mEasyLogin.onActivityResult(requestCode, resultCode, data);
        }
    
    
        @Override
        public void onLoginSuccess(SocialNetwork.Network network) {
            if (network == SocialNetwork.Network.FACEBOOK) {
                AccessToken token = mEasyLogin.getSocialNetwork(SocialNetwork.Network.FACEBOOK).getAccessToken();
                String fbtok = token.getToken();
                System.out.println(fbtok);
            }else if (network == SocialNetwork.Network.GOOGLE_PLUS) {
                AccessToken token = mEasyLogin.getSocialNetwork(SocialNetwork.Network.GOOGLE_PLUS).getAccessToken();
                String gptok = token.getToken();
                System.out.println(gptok);
            }
        }
    
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            EasyLogin.initialize();
            mEasyLogin = EasyLogin.getInstance();
    
            view = inflater.inflate(R.layout.page_login_fragment, container, false);
    
            // FACEBOOK
            fbScope = new ArrayList<>();
            fbScope.addAll(Collections.singletonList("public_profile, email"));
            mEasyLogin.addSocialNetwork(new FacebookNetwork((MainActivity)getActivity(), fbScope));
    
            facebook = (FacebookNetwork) mEasyLogin.getSocialNetwork(SocialNetwork.Network.FACEBOOK);
            facebook.setOnLoginCompleteListener(this);
            loginButton = (LoginButton) view.findViewById(R.id.login_button);
            // Call this method if you are using the LoginButton provided by facebook
            // It can handle its own state
            if (!facebook.isConnected()) {
                facebook.requestLogin(loginButton,this);
            }
    
            mEasyLogin.addSocialNetwork(new GooglePlusNetwork((MainActivity)getActivity()));
            gPlusNetwork = (GooglePlusNetwork) mEasyLogin.getSocialNetwork(SocialNetwork.Network.GOOGLE_PLUS);
            gPlusNetwork.setOnLoginCompleteListener(this);
    
            gPlusButton = (SignInButton) view.findViewById(R.id.gplus_sign_in_button);
            gPlusButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!gPlusNetwork.isConnected()) {
                        gPlusNetwork.requestLogin(PageLoginFragment.this);
                    }
                }
            });
    
    
    
            updateStatuses();
    
            return view;
        }
    
        private void updateStatuses() {
            StringBuilder content = new StringBuilder();
            for (SocialNetwork socialNetwork : mEasyLogin.getInitializedSocialNetworks()) {
                content.append(socialNetwork.getNetwork())
                        .append(": ")
                        .append(socialNetwork.isConnected())
                        .append("\n");
            }
            System.out.println(content.toString());
        }
    
        @Override
        public void onError(SocialNetwork.Network socialNetwork, String requestID, String errorMessage) {
            Log.e("MAIN", "ERROR!" + socialNetwork + "|||" + errorMessage);
    
        }
    }
    
    opened by stepenik 16
  • Social network with id = FACEBOOK already exists

    Social network with id = FACEBOOK already exists

    EasyLogin.initialize(); easyLogin = EasyLogin.getInstance();

    List fbScope = Arrays.asList("public_profile", "email");

    // error occurs on this line easyLogin.addSocialNetwork(new FacebookNetwork(this, fbScope));

    What should I do to avoid this Exception?

    opened by MoliByte 4
  • How to get the logged in users image uri?

    How to get the logged in users image uri?

    The global access token method has only name email and id set.But for sign in purpose,including the profile picture uri is necessary ,and i cant find any way of manually doing that as the SignInResult object is not available.

    opened by shopip 4
  • Implement in Fragment

    Implement in Fragment

    Can this work in class which extends Fragment

    public class PageLoginFragment extends Fragment implements OnLoginCompleteListener {
    }
    

    This not work, can you give example of class?

       @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            EasyLogin.initialize();
            mEasyLogin = EasyLogin.getInstance();
    
            View view = inflater.inflate(R.layout.page_login_fragment, container, false);
    
            // FACEBOOK
            fbScope = new ArrayList<>();
            fbScope.addAll(Collections.singletonList("public_profile, email"));
            mEasyLogin.addSocialNetwork(new FacebookNetwork(getActivity(), fbScope));
    
            facebook = (FacebookNetwork) mEasyLogin.getSocialNetwork(SocialNetwork.Network.FACEBOOK);
            facebook.setOnLoginCompleteListener(this);
            loginButton = (LoginButton) view.findViewById(R.id.login_button);
            // Call this method if you are using the LoginButton provided by facebook
            // It can handle its own state
            if (!facebook.isConnected()) {
                facebook.requestLogin(loginButton,this);
            }
    
            updateStatuses();
    
            return view;
        }
    
    

    But never call event onError or onLoginSuccess

    opened by stepenik 2
  • custom Button

    custom Button

    Hello Mak,

    I want to use my own custom made button. how i can use without using your social button. if there is not option at least how i can update the text in your button.

    opened by boygaggoo 1
  • Modularization

    Modularization

    It could be valuable to just include the social networks you really need into the project (although proguard strips off unneeded methods) --> Modularize dependencies

    enhancement 
    opened by maksim88 0
Releases(v0.6)
Owner
Maksim
Maksim
Library for easy work with Facebook, Twitter, LinkedIn and Google on Android

THIS PROJECT IS NO LONGER MAINTAINED, FEEL FREE TO FORK AND FIX IT FOR YOUR NEEDS There is also an Android Library that is being maintained, CloudRail

Anton Krasov 1k Dec 18, 2022
Simple Twitter Client just for tweeting, written in Kotlin with reactive MVVM-like approach

Monotweety Simple Twitter Client just for tweeting. Monotweety is also available at F-Droid compatible repository called IzzyOnDroid F-Droid Repositor

Yasuhiro SHIMIZU 110 Nov 11, 2022
Yet another Twitter unofficial client for Lollipop.

Tweetin Yet another Twitter unofficial client. Just design for Lollipop now!!! Screenshot: How to use the source code? Just import the Tweetin folder

Matthew Lee 177 Aug 24, 2022
Material Design ready and feature rich Twitter/Mastodon/Fanfou app for Android 4.1+.

Twidere for Android Material Design ready and feature rich Twitter/Mastodon/Fanfou app for Android 4.1+. Enjoy Fediverse now! Twidere-Android is maint

Twidere Project 2.7k Jan 1, 2023
KTweet is a Kotlin Library that allows you to consume the Twitter API v2.

KTweet - A Kotlin Twitter Library KTweet is a library that allows you to use the Twitter API v2. Interested in Kotlin or KTweet? Join the Discord Setu

Thomas Carney 26 Dec 22, 2022
Share twitter url to this app, and you will be redirected.

twitter2nitter - redirect twitter to nitter Share twitter url to this app, and you will be redirected. Redirect works for: Open twitter url with twitt

null 14 Dec 20, 2022
Status Stories = Snapchat stories, Instagram stories, Whatsapp Statuses, Facebook Messenger Stories.

StatusStories APK Link | Video Link | Up labs StatusStories helps you implement Photo Stories similar to Snapchat stories Instagram stories Whatsapp S

Rahul Janagouda 335 Jan 4, 2023
A Social Media Application with a Chatbot.

Acro Chat A Social Media Android app build in using Features- Posts, Chat with Users, Profile Page, Chat bot Preview Home Page Messages Chat Bot Licen

Sachin Lohar 14 Aug 3, 2022
The Google I/O Android App

Google I/O Android App 2021 Update Due to global events, Google I/O 2020 was canceled and Google I/O 2021 is an online-only event, so the companion ap

Google 21.7k Jan 7, 2023
Android Stories library - Instagram-like android stories library that supports images from disk or from internet (url)

Android Stories Library Instagram like stories library for Android. Add it in your root build.gradle at the end of repositories: allprojects { reposi

Panagiotis Makris 3 Dec 20, 2022
Easy social network authorization for Android. Supports Facebook, Twitter, Instagram, Google+, Vkontakte. Made by Stfalcon

SocialAuthHelper A library that helps to implement social network authorization (Facebook, Twitter, Instagram, GooglePlus, Vkontakte). Who we are Need

Stfalcon LLC 97 Nov 24, 2022
Android Ad Manager Works with Admob, Mopup, Facebook- Bidding and Audience Networks

AndroidAdManager Works with Admob, Mopup, Facebook- Bidding and Audience Networks. Added ad types are NativeBanner, NativeAdvanced, Interstitial and B

Hashim Tahir 11 May 18, 2022
Library for easy work with Facebook, Twitter, LinkedIn and Google on Android

THIS PROJECT IS NO LONGER MAINTAINED, FEEL FREE TO FORK AND FIX IT FOR YOUR NEEDS There is also an Android Library that is being maintained, CloudRail

Anton Krasov 1k Dec 18, 2022
Awesome Android Typeahead library - User mention plugin, UI widget for auto complete user mention using the at sign (@) like Twitter or Facebook.

android-typeahead Awesome Android Typeahead library - User mention plugin, UI widget for auto complete user mention using the at sign (@) like Twitter

Arab Agile 11 Jun 4, 2019
An open-source Android app for locating your group's people privately using Facebook Login, Google Maps API and Firebase

An open-source Android app for locating your group's people privately using Facebook Login, Google Maps API and Firebase

Duong Tran Thanh 2 Feb 27, 2022
A Flutter plugin thats support share files to social media like TikTok, Instagram, Facebook, WhatsApp, Telegram and more others...

Social Share Kit A Flutter plugin that's support share files to social media like Tiktok, Instagram, Facebook, WhatsApp, Telegram and more. This plugi

Kaique Gazola 2 Sep 2, 2022
Twidere-Android Twidere is a powerful twitter client for Android 1.6+ 1 , which gives you a full Holo experience and nearly full Twitter's feature.

Twidere for Android Material Design ready and feature rich Twitter/Mastodon/Fanfou app for Android 4.1+. Enjoy Fediverse now! Twidere-Android is maint

Twidere Project 2.7k Jan 2, 2023
📦📦Video downloader for Android - Download videos from Youtube, Facebook, Twitter, Instagram, Dailymotion, Vimeo and more than 1000 other sites

youtube-dl-android ?? An Android client for youtube-dl: https://github.com/rg3/youtube-dl Major technologies Language: Kotlin Architecture: MVVM Andro

Cuong Pham 445 Jan 8, 2023
📦📦Video downloader for Android - Download videos from Youtube, Facebook, Twitter, Instagram, Dailymotion, Vimeo and more than 1000 other sites

youtube-dl-android ?? An Android client for youtube-dl: https://github.com/rg3/youtube-dl Major technologies Language: Kotlin Architecture: MVVM Andro

Cuong Pham 443 Dec 30, 2022