Easy social network authorization for Android. Supports Facebook, Twitter, Instagram, Google+, Vkontakte. Made by Stfalcon

Overview

SocialAuthHelper

A library that helps to implement social network authorization (Facebook, Twitter, Instagram, GooglePlus, Vkontakte).

Who we are

Need iOS and Android apps, MVP development or prototyping? Contact us via [email protected]. We develop software since 2009, and we're known experts in this field. Check out our portfolio and see more libraries from stfalcon-studio.

Download

Download via Gradle:

compile 'com.github.stfalcon:socialauthhelper:0.1'

or Maven:

<dependency>
  <groupId>com.github.stfalcon</groupId>
  <artifactId>socialauthhelper</artifactId>
  <version>0.1.1</version>
  <type>pom</type>
</dependency>

Usage

If you don't use fabric plugin for Android studio, put it into gradle:

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

dependencies {
    //your dependencies
    compile ('com.twitter.sdk.android:twitter:1.13.2@aar') {
        transitive = true;
    }
}

Twitter

Create new application at https://apps.twitter.com
Don't forget to enable: "Allow this application to be used to Sign in with Twitter."
In Application class or initial activity class:

TwitterAuthConfig authConfig = new TwitterAuthConfig(
                getString(R.string.twitterConsumerKey),//twitter application consumer key
                getString(R.string.twitterConsumerSecret));//twitter application consumer secret
//setup fabric
Fabric.with(this, new Twitter(authConfig));

In your activity(fragment) class declare field:

private TwitterClient twitterClient;

In onCreate method:

//create TwitterClient where `this` is your activity
twitterClient = new TwitterClient(this);

//init views
final Button btnTwitter = (Button) findViewById(R.id.btn_twitter);
final TextView tvTwitter = (TextView) findViewById(R.id.tv_twitter);
final ImageView ivTwitter = (ImageView) findViewById(R.id.iv_twitter);

//set onClick event for auth button
btnTwitter.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      twitterClient.getUser(new TwitterClient.UserLoadListener() {
        @Override
        public void onUserLoaded(User user, String profileImage) {
            //after authorization successful you have access to user profile and Access Token
            tvTwitter.setText(getString(R.string.profileInfo,
                  user.name,
                  user.getId(),
                  twitterClient.getAccessToken()));

            Picasso.with(MainActivity.this).load(profileImage).into(ivTwitter);
      }
});

Override onActivityResult method:

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

Vkontakte

Create new application at https://vk.com/dev
In your activity(fragment) class declare field:

private VkClient vkClient;

In onCreate method:

//create VkClient where `this` is your activity
vkClient = new VkClient(this, //activity or fragment
    getString(R.string.vk_redirect_uri), //vk application redirect uri
    getString(R.string.vk_client_id)); //vk application clientId

//init views
final Button btnVk = (Button) findViewById(R.id.btn_vk);
final TextView tvVk = (TextView) findViewById(R.id.tv_vk);
final ImageView ivVk = (ImageView) findViewById(R.id.iv_vk);
//set onClick event for auth button
btnVk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            vkClient.getProfile(new VkClient.DataLoadedListener<VkProfile>() {
                @Override
                public void onDataLoaded(VkProfile vkProfile) {
                  //after authorization successful you have access to user profile and Access Token
                  tvVk.setText(getString(R.string.profileInfo,
                      vkProfile.getFirstName() + " " + vkProfile.getLastName(),
                      vkProfile.getId(),
                      vkClient.getAccessToken()));
                      
                  Picasso.with(MainActivity.this).load(vkProfile.getProfilePhoto()).into(ivVk);
                }
            });
        }
});

Override onActivityResult method:

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

Facebook

Create new application at https://developers.facebook.com/apps
In AndroidManifest:

<activity
    android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<provider
    android:name="com.facebook.FacebookContentProvider"
    android:authorities="com.facebook.app.FacebookContentProvider<Your facebook application ID>"
    android:exported="true" />
<meta-data
    android:name="com.facebook.sdk.ApplicationId"
    android:value="<Your facebook application ID>" />

In your activity(fragment) class declare field:

private FacebookClient facebookClient;

In onCreate method:

facebookClient = new FacebookClient(this);

//init views
final Button btnFacebook = (Button) findViewById(R.id.btn_facebook);
final TextView tvFacebook = (TextView) findViewById(R.id.tv_facebook);
final ImageView ivFacebook = (ImageView) findViewById(R.id.iv_facebook);

//set onClick event for auth button
btnFacebook.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
    facebookClient.getProfile(new FacebookClient.FbResultCallback() {
        @Override
        public void onProfileLoaded(FacebookProfile facebookProfile) {
            //after authorization successful you have access to user profile and Access Token
            tvFacebook.setText(getString(R.string.profileInfo,
                    facebookProfile.getName(),
                    facebookProfile.getId(),
                    facebookClient.getToken()));
                    
            Picasso.with(MainActivity.this).load(
                    facebookProfile.getPicture().data.url).into(ivFacebook);
        }
    });
}
});

Override onActivityResult method:

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

Google+

Create new application at https://console.developers.google.com/
Don't forget to enable google plus api.
In your activity(fragment) class declare field:

private GooglePlusClient googlePlusClient;

In onCreate method:

googlePlusClient = new GooglePlusClient(this, 
    getString(R.string.googleClientId));//Web client id

//init views
final Button btnGoogle = (Button) findViewById(R.id.btn_google);
final TextView tvGoogle = (TextView) findViewById(R.id.tv_google);
final ImageView ivGoogle = (ImageView) findViewById(R.id.iv_google);
        
//set onClick event for auth button
btnGoogle.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      googlePlusClient.getProfile(new GooglePlusClient.GooglePlusResultCallback() {
          @Override
          public void onProfileLoaded(GooglePlusProfile googlePlusProfile) {
              //after authorization successful you have access to user profile and Access Token
              tvGoogle.setText(getString(R.string.profileInfo,
                      googlePlusProfile.getName(),
                      googlePlusProfile.getId(),
                      facebookClient.getToken()));
                      
              Picasso.with(MainActivity.this).load(
                      googlePlusProfile.getAvatar()).into(ivGoogle);
          }
      });
    }
});

Override onActivityResult method:

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

Instagram

Create new application at https://www.instagram.com/developer/clients/manage/
Don't forget to enable implicit OAuth in application security settings.

In your activity(fragment) class declare field:

private InstagramClient instagramClient;

In onCreate method:

instagramClient = new InstagramClient(this,
                getString(R.string.instagramRedirectUri), //instagram application redirect uri
                getString(R.string.instagramClientId)); //instagram application client id

//init views
final Button btnInstagram = (Button) findViewById(R.id.btn_instagram);
final TextView tvInstagram = (TextView) findViewById(R.id.tv_instagram);
final ImageView ivInstagram = (ImageView) findViewById(R.id.iv_instagram);

//set onClick event for auth button
btnInstagram.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        instagramClient.getProfile(new InstagramClient.DataLoadedListener<InstagramProfile>() {
            @Override
            public void onDataLoaded(InstagramProfile instagramProfile) {
                //after authorization successful you have access to user profile and Access Token
                tvInstagram.setText(getString(R.string.profileInfo,
                        instagramProfile.getFullName(),
                        instagramProfile.getId(),
                        facebookClient.getToken()));
                        
                Picasso.with(MainActivity.this).load(
                        instagramProfile.getProfilePicture()).into(ivInstagram);
            }
        });
    }
});

Override onActivityResult method:

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

Take a look at the sample projects for more information

License

Copyright 2017 stfalcon.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
Implementation of Instagram with Material Design (originally based on Emmanuel Pacamalan's concept)
Implementation of Instagram with Material Design (originally based on Emmanuel Pacamalan's concept)

InstaMaterial Updated Current source code contains UI elements from Design Support Library. If you still want to see how custom implementations of e.g

A basic instagram clone
A basic instagram clone

Instafire A Approach of making instagram clone. Used kotlin for making and firebase firestore for storing and uploading data. One can login and logout

The Google I/O Android App
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

Youtube-dl for android

youtube-dl-android Android library wrapper for youtube-dl executable. Based on yausername's youtubedl-android but with ability to download binary file

Twidere for Android

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

A Reddit client for Android

This is a Reddit client on Android written in Java. It does not have any ads and it features clean UI and smooth browsing experience.

An unofficial open source Reddit client for Android.

RedReader An unofficial, open source Android client for Reddit. Features Free and open-source Software - no ads/tracking Lightweight and fast Swipe po

Slide is an open sourced, ad free Reddit browser for Android
Slide is an open sourced, ad free Reddit browser for Android

Slide Slide is an open source, ad free Reddit browser for Android. It is based around the Java Reddit API Wrapper. Slide is available on the Google Pl

Kickstarter for Android. Bring new ideas to life, anywhere.

Welcome to Kickstarter's open source Android app! Come on in, take your shoes off, stay a while—explore how Kickstarter's native squad has built and c

Comments
  • add email field on facebook client , select picture size

    add email field on facebook client , select picture size

    • add email field on facebook client to retrieve loggedin user email
    • select picture size " The size of this picture. It can be one of the following values: small, normal, large, square." from api docs. [ default is small ]
    opened by meltaweel 1
  • Suggestions

    Suggestions

    Can you upload new version with updated dependencies and add ability to disable token caching? As I read in facebook docs, after user has changed his password token must become invalid, but it's not, and user can still get it from cache (preferences) and use. Which is not good. Also it would be good to have callbacks for logout and unsuccessful login events

    opened by F0RIS 0
Owner
Stfalcon LLC
We specialize in the development of large and medium-sized projects, mobile and web applications, portals with a complex and rich functionality.
Stfalcon LLC
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
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
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
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
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
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
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
Open-source alternative Instagram client on Android.

Instagram client; previously known as InstaGrabber.

Austin Huang 1.1k Jul 23, 2021