Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stfalcon-studio/socialauthhelper

Easy social network authorization for Android. Supports Facebook, Twitter, Instagram, Google+, Vkontakte. Made by Stfalcon
https://github.com/stfalcon-studio/socialauthhelper

android authorization facebook googleplus instagram twitter vkontakte

Last synced: 8 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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](https://stfalcon.com/en/portfolio) and see more libraries from [stfalcon-studio](https://stfalcon-studio.github.io/).

## Download

Download via Gradle:
```gradle
compile 'com.github.stfalcon:socialauthhelper:0.1'
```

or Maven:
```xml

com.github.stfalcon
socialauthhelper
0.1.1
pom

```

## Usage

If you don't use fabric plugin for Android studio, put it into gradle:
```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:
```java
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:
```java
private TwitterClient twitterClient;
```
In onCreate method:
```java
//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:
```java
@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:
```java
private VkClient vkClient;
```
In onCreate method:
```java
//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() {
@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:
```java
@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:
```xml

```

In your activity(fragment) class declare field:
```java
private FacebookClient facebookClient;
```
In onCreate method:
```java
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:
```java
@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:
```java
private GooglePlusClient googlePlusClient;
```
In onCreate method:
```java
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:
```java
@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:
```java
private InstagramClient instagramClient;
```
In onCreate method:
```java
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() {
@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:
```java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
instagramClient.onActivityResult(requestCode, resultCode, data);
}
```

Take a look at the [sample projects](sample) 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.
```

[sample]: