GithubHelp home page GithubHelp logo

essocialsdk's Introduction

ESSocialSDK Build Status

社交登录授权,分享SDK
支持微信、微博、QQ登录授权
微信好友、微信朋友圈、微博、QQ好友、QQ空间分享

Gradle

compile 'com.elbbbird.android:socialsdk:0.1.0@aar'

使用指南

Debug模式

SocialSDK.setDebugMode(true); //默认false

平台SSO授权功能

ISocialOauthCallback授权回调接口

授权结果回调

SDK使用了Otto作为事件库,用以组件通信。(其实我是不想写startActivityForResult ...)
在调用SocialSDK.oauth()接口ActivityonCreate()方法内添加

BusProvider.getInstance().register(this);

在该ActivityonDestroy()方法添加

@Override
protected void onDestroy() {
    BusProvider.getInstance().unregister(this);
    super.onDestroy();
}

添加回调接口

@Subscribe
public void onOauthResult(BusEvent event) {
    switch (event.getType()) {
        case BusEvent.TYPE_GET_TOKEN:
            SocialToken token = event.getToken();
            Log.i(TAG, "onOauthResult#BusEvent.TYPE_GET_TOKEN " + token.toString());
            break;
        case BusEvent.TYPE_GET_USER:
            SocialUser user = event.getUser();
            Log.i(TAG, "onOauthResult#BusEvent.TYPE_GET_USER " + user.toString());
            break;
        case BusEvent.TYPE_FAILURE:
            Exception e = event.getException();
            Log.i(TAG, "onOauthResult#BusEvent.TYPE_FAILURE " + e.toString());
            break;
        case BusEvent.TYPE_CANCEL:
            Log.i(TAG, "onOauthResult#BusEvent.TYPE_CANCEL");
            break;
    }
}

微博授权

  • 配置微博后台回调地址
    SDK的默认回调地址为http://www.sina.com,需要在微博后台配置,否则会提示回调地址错误。
    如果在SocialSDK.initWeibo()方法自定义了回调地址,需要在后台配置为相应地址。
  • oauth
SocialSDK.initWeibo("app_key");
SocialSDK.oauthWeibo(context);
  • onActivityResult
SocialSDK.oauthWeiboCallback(context, requestCode, resultCode, data);
  • revoke
SocialSDK.revokeWeibo(context);

微信授权

  • WXEntryActivity
    创建包名:package_name.wxapi
    在该包名下创建类WXEntryActivity继承自WXCallbackActivity
package com.encore.actionnow.wxapi;
public class WXEntryActivity extends WXCallbackActivity {

}
  • AndroidManifest.xml
<activity
    android:name=".wxapi.WXEntryActivity"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:exported="true"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />
  • oauth
SocialSDK.initWeChat("app_id", "app_secret");
SocialSDK.oauthWeChat(context);
  • revoke
SocialSDK.revokeWeChat(context);

QQ授权

  • AndroidManifest.xml
<activity
    android:name="com.tencent.tauth.AuthActivity"
    android:launchMode="singleTask"
    android:noHistory="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data android:scheme="tencentXXXXXXXXX" />
    </intent-filter>
</activity>

以上配置中的XXXXXXXXX换成app_id.

  • oauth
SocialSDK.initQQ(app_id);
SocialSDK.oauthQQ(context);
  • onActivityResult
if (requestCode == Constants.REQUEST_LOGIN || requestCode == Constants.REQUEST_APPBAR) {
    SocialSDK.oauthQQCallback(requestCode, resultCode, data);
}
  • revoke
SocialSDK.revokeQQ(context);

SDK默认授权界面,展示全平台授权接口

  • 配置微博后台回调地址
    SDK的默认回调地址为http://www.sina.com,需要在微博后台配置,否则会提示回调地址错误。
    如果在SocialSDK.init()方法自定义了回调地址,需要在后台配置为相应地址。

  • WXEntryActivity
    创建包名:package_name.wxapi
    在该包名下创建类WXEntryActivity继承自WXCallbackActivity

package com.encore.actionnow.wxapi;
public class WXEntryActivity extends WXCallbackActivity {

}
  • AndroidManifest.xml
<activity
    android:name=".wxapi.WXEntryActivity"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:exported="true"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
    android:name="com.tencent.tauth.AuthActivity"
    android:launchMode="singleTask"
    android:noHistory="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data android:scheme="tencentXXXXXXXXX" />
    </intent-filter>
</activity>

以上配置中的XXXXXXXXX换成app_id.

  • oauth
SocialSDK.init("wechat_app_id", "wechat_app_secret", "weibo_app_id", "qq_app_id");
SocialSDK.oauth(context);
  • revoke
SocialSDK.revoke(context);

FAQ

  • 关于三个平台的账号
    微博应用程序注册完成后,需要在后台配置测试账号,包名,签名信息,然后开始测试;
    微信应用程序注册后,需要配置包名和签名,并提交审核通过,可以获得分享权限。SSO登录权限需要开发者认证。(保护费不到位,测试都不能做)
    QQ需要在后台配置测试账号才能SSO登录。

  • 是否需要配置权限?
    SDK已经在aar中添加三个平台需要的权限,以下

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  • ProGrard代码混淆

essocialsdk's People

Contributors

hailong0707 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.