Android-Federated Third Party Login and Sharing

Preface

Recent projects once again require the integration of tripartite logins and sharing of federations, which has not been recorded before, so write this time...

Dead work

1. Register an affiliate account to create an application and get the key:application address http://www.umeng.com
2. Apply for third-party accounts for corresponding platforms (Tencent, WeChat, Sina, etc.) to obtain key s and passwords

Integration steps

Because shareSDK sharing is similar to third-party login integration (sharing jar packages), I'll just go ahead.

1. Download shareSDK Shared SDK

Download address: https://developer.umeng.com/sdk

2. Import jar and res

Open the development document and download the corresponding SDK and demo. Select the features you need to download the SDK

The functions of the downloaded file are as follows:

Import into Android studio and add dependencies

3. Configure Android Manifest XML

Required Activities in sdk

  • Sina
   <activity
        android:name="com.umeng.socialize.media.WBShareCallBackActivity"
        android:configChanges="keyboardHidden|orientation"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"
        android:exported="false"
        >
    </activity>
    <activity android:name="com.sina.weibo.sdk.web.WeiboSdkWebActivity"
              android:configChanges="keyboardHidden|orientation"
              android:exported="false"
              android:windowSoftInputMode="adjustResize"
    >

    </activity>
    <activity
        android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
        android:launchMode="singleTask"
        android:name="com.sina.weibo.sdk.share.WbShareTransActivity">
        <intent-filter>
            <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

    </activity>
  • WeChat
 <activity
            android:name=".wxapi.WXEntryActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:exported="true"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
  • QQ
     <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="tencent100424468" />
        </intent-filter>
        </activity>
        <activity
        android:name="com.tencent.connect.common.AssistActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"
        android:configChanges="orientation|keyboardHidden|screenSize"/>

Add permissions:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Adaptation

Android 6.0 Rights Adaptation

if(Build.VERSION.SDK_INT>=23){
                  String[] mPermissionList = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.CALL_PHONE,Manifest.permission.READ_LOGS,Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.SET_DEBUG_APP,Manifest.permission.SYSTEM_ALERT_WINDOW,Manifest.permission.GET_ACCOUNTS,Manifest.permission.WRITE_APN_SETTINGS};
                  ActivityCompat.requestPermissions(this,mPermissionList,123);
              }

Of these, 123 is the request code, which determines whether the user has agreed to authorize.If you do not agree, you can proceed with the callback accordingly:

@Override
public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {

}
Initialization Settings
@Override
    public void onCreate() {
        super.onCreate();
        UMConfigure.init(this,"5a12384aa40fa3551f0001d1"
                ,"umeng",UMConfigure.DEVICE_TYPE_PHONE,"");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0

    }

Next, you need to set the appkey for each platform:

        PlatformConfig.setWeixin("wxdc1e388c3822c80b", "3baf1193c85774b3fd9d18447d76cab0");
        //Douban RENREN platform is currently configurable only on the server side
        PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad","http://sns.whalecloud.com");
        PlatformConfig.setYixin("yxc0614e80c9304c11b0391514d09f13bf");
        PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
        PlatformConfig.setTwitter("3aIN7fuF685MuZ7jtXkQxalyi", "MK6FEYG63eWcpDFgRYw4w9puJhzDl0tyuqWjZ3M7XJuuG7mMbO");
        PlatformConfig.setAlipay("2015111700822536");
        PlatformConfig.setLaiwang("laiwangd497e70d4", "d497e70d4c3e4efeab1381476bac4c5e");
        PlatformConfig.setPinterest("1439206");
        PlatformConfig.setKakao("e4f60e065048eb031e235c806b31c70f");
        PlatformConfig.setDing("dingoalmlnohc0wggfedpk");
        PlatformConfig.setVKontakte("5764965","5My6SNliAaLxEm3Lyd9J");
        PlatformConfig.setDropbox("oz8v5apet3arcdy","h7p2pjbzkkxt02a");
        PlatformConfig.setYnote("9c82bf470cba7bd2f1819b0ee26f86c6ce670e9b");
autograph

You must test with an apk signed by the keystore. If the signature file is not added, authorization for some platforms will be affected.

Use steps

1. Sharing

There are two forms of alliance sharing:

With Sharing on the Sharing Panel, users can invoke our method of opening the Sharing Panel and click on the corresponding platform of the Sharing Panel to share.
Instead of sharing on the Share panel, users can write the Share button themselves, or trigger events, and then call our Share Method to share.In short, direct sharing is inserting a sharing behavior into the user's own interface components, and the sharing panel is an interface component that opens one of our written components and shares it based on clicks.

The code to open the sharing panel is as follows:

new ShareAction(MainActivity.this)
.setPlatform(SHARE_MEDIA.QQ)//Inbound Platform
.withText("hello")//Share content
.setCallback(umShareListener)//Callback listener
.share();

There are many types of sharing, see the Federated Developer Documentation, here is a connection example:
Sharing links can be shared using UMWeb:

UMWeb  web = new UMWeb(Defaultcontent.url);
        web.setTitle("This is music title");//Title
        web.setThumb(thumb);  //thumbnail
        web.setDescription("my description");//describe

Then the call sets this parameter to ShareAction:

new ShareAction(ShareActivity.this)
    .withMedia(web)
    .share();
2. Third party login

There are two scenarios for third-party logins:

Authorization interface to obtain user data, which can be used to obtain all the data returned by the three-party platform (including name, gender, avatar, etc.) Current platforms that support third-party login include:

Domestic Platform (Weixin, Sina Weibo, QQ, Douban, Everyone)

Foreign platforms (Facebook, Twitter, linkedIn, kakao, VKontakte, Dropbox)

It is recommended that you use the first method directly, because essentially, a tripartite login will ultimately require pulling user data from the tripartite platform. From this point of view, calling SDK directly is the same security as requesting it through a background server.

There are two scenarios for third-party logins:

Authorization interface to obtain user data, which can be used to obtain all the data returned by the three-party platform (including name, gender, avatar, etc.) Current platforms that support third-party login include:

Domestic Platform (Weixin, Sina Weibo, QQ, Douban, Everyone)

Foreign platforms (Facebook, Twitter, linkedIn, kakao, VKontakte, Dropbox)

It is recommended that you use the first method directly, because essentially, a tripartite login will ultimately require pulling user data from the tripartite platform. From this point of view, calling SDK directly is the same security as requesting it through a background server.

Get User Data

The following interfaces can be used to obtain user data:

mShareAPI.getPlatformInfo(UserinfoActivity.this, SHARE_MEDIA.SINA, umAuthListener);

Among them, umAuthListener is an authorization callback, which is constructed as follows:

UMAuthListener authListener = new UMAuthListener() {
        /**
         * @desc Callback for Authorization Start
         * @param platform Platform Name
         */
        @Override
        public void onStart(SHARE_MEDIA platform) {

        }

        /**
         * @desc Callback for successful authorization
         * @param platform Platform Name
         * @param action Behavior Sequence Number Not Used by Developers
         * @param data User Data Return
         */
        @Override
        public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {

            Toast.makeText(mContext, "Succeed", Toast.LENGTH_LONG).show();

       }

        /**
         * @desc Callback for Authorization Failure
         * @param platform Platform Name
         * @param action Behavior Sequence Number Not Used by Developers
         * @param t Error Reason
         */
        @Override
       public void onError(SHARE_MEDIA platform, int action, Throwable t) {

           Toast.makeText(mContext, "Failure:" + t.getMessage(),                                     Toast.LENGTH_LONG).show();
        }

        /**
         * @desc Callback for Authorization Cancellation
         * @param platform Platform Name
         * @param action Behavior Sequence Number Not Used by Developers
         */
        @Override
        public void onCancel(SHARE_MEDIA platform, int action) {
            Toast.makeText(mContext, "Cancelled", Toast.LENGTH_LONG).show();
        }
    };  

After successful login, third-party platforms will return user data, all in Map data.

There are also other features you can view the Federation Development documentation at:
https://developer.umeng.com/d...

You can pay attention to my WeChat public number: "Commander Qin" is a public number with quality and attitude!

Tags: Android SDK xml

Posted on Fri, 06 Sep 2019 18:11:27 -0700 by sillysillysilly