ShareSDK MOB third party sharing including tiktok sharing

MobSDK {
    appKey "888888888888888888"
    appSecret "888888888888888888"

    ShareSDK {
        //Platform configuration information
        devInfo {
            SinaWeibo {
                appKey "888888888888888888"
                appSecret "888888888888888888"
                callbackUri "address configured to Sina"
            }
            Wechat {
                appId "888888888888888888"
                appSecret "888888888888888888"
            }
            WechatMoments {
                appId "888888888888888888"
                appSecret "888888888888888888"
            }
            WechatFavorite {
                appId "888888888888888888"
                appSecret "888888888888888888"
            }
            QQ {
                appId "888888888888888888"
                appKey "888888888888888888"
            }
            QZone {
                appId "888888888888888888"
                appKey "888888888888888888"
            }
           
        }
    }
}
If you need to share any platform, just add it. If you have any questions, please leave a message to me

1, Integration preparation

1. Register AppKey and AppSecret of application Mob

2. You need to apply for the key of the third-party platform

Note: using the ShareSDK Gradle integration mode, you do not need to configure any permissions and activities under AndroidMainfest.xml

2, Integrated configuration

1. Open build.gradle in the root directory of the project, and add classpath 'com.mob.sdk:MobSDK:2018.0319.1724' under the buildscrip t - > dependencies module, as shown below;

buildscript {
    repositories {
        ...
    }
    dependencies {
        ...
        classpath "com.mob.sdk:MobSDK:2018.0319.1724"
    }
}

2. Add a reference to the build.gradle file under the module of the Mob product

apply plugin: 'com.mob.sdk'

3. Then add the MobSDK method to configure the key and secret key of mob (step 2 is a gradle; note: the MobSDK method is to configure to the root directory of the file, side by side with android, not android)

MobSDK {
    appKey "Apply Mob Of appkey"
    appSecret "Apply Mob Of AppSecret"
    ShareSDK {} 
}

4. In the Gradle integration mode, you can configure the key information of each social platform of the ShareSDK in the build.gradle file under the module of the Mob product

MobSDK {
    appKey "Apply Mob Of appkey"
    appSecret "Apply Mob Of AppSecret"

    ShareSDK {
        //Platform configuration information
        devInfo {
            Wechat {
                appId "wx4868b35061f87885"
                appSecret "64020361b8ec4c99936c0e3999a9f249"
            }
            QQ {
                appId "100371282"
                appKey "aed9b0303e3ed1e27bae87c33761161d"
                shareByAppClient true
            }
            Facebook {
                appKey "1412473428822331"
                appSecret "a42f4f3f867dc947b9ed6020c2e93558"
                callbackUri "https://mob.com"
            }
            SinaWeibo {
                appKey "568898243"
                appSecret "38a4f8204cc784f81f9f0daaf31e02e3"
                callbackUri "http://www.sharesdk.cn"
                shareByAppClient true
            }
        }
    }
}

Among them, devInfo is the application information from the social platform, with complete platform parameters Please click here for details ; specific field parameter description, etc, Click here for details

3, Add code

According to the requirements of national laws and regulations (for details, please refer to the document issued by the network security administration of the Ministry of industry and information technology of the people's Republic of China Identification method for illegal collection and use of personal information by App When using the SDK products provided by MobTech, developers need to show the privacy service agreement of MobTech to end users and obtain the authorization of users.

MobTech provides the corresponding interface of privacy service for developers to use.

Note: all developers must access the MobTech privacy service process in accordance with this document, otherwise it may cause failure to use the relevant services provided by each SDK of MobTech.

MobTech privacy service process access guide

In the MobTech privacy process, it mainly includes "privacy agreement authorization" and "viewing the content of MobTech privacy agreement". The interfaces involved are as follows:

1. Show the MobTech privacy protocol to the end user and return the user authorization result

2. Query the content of MobTech privacy agreement

Privacy agreement authorization

Show MobTech privacy agreement: developers need to show MobTech privacy terms and return the agreed results to MobTech. The following methods are recommended:

Embed the URL of MobTech privacy protocol into the description of app privacy protocol (recommended)

Step 1: recommend adding privacy policy text: in order to realize sharing and push functions, we use MobTech's ShareSDK product. For the privacy policy terms of this product, please refer to: http://www.mob.com/about/policy

Step 2: return the user authorization result

When the end user makes a choice on the privacy protocol pop-up box, the developer shall send back the authorization result to the SDK in time, no matter whether they agree or refuse.

Interface parameter
MobSDK.submitPolicyGrantResult(boolean granted, OperationCallback callback) Does grant agree to the privacy agreement
Callback result callback, null able

Sample code

The invocation location developers can make their own calls only if they use the SDK function.

 private void submitPrivacyGrantResult(boolean granted) {
        MobSDK.submitPolicyGrantResult(granted, new OperationCallback<Void>() {
            @Override
            public void onComplete(Void data) {
                Log.d(TAG, "Privacy agreement authorization result submission: success");
            }

            @Override
            public void onFailure(Throwable t) {
                Log.d(TAG, "Privacy agreement authorization result submission: failed");
            }
        });
    }

Note: this interface must be accessed, otherwise it may not be able to use the relevant services provided by each SDK of MobTech. At this point, the result will be sent back to Mob and it will be finished

Other embedding methods can refer to: Other presentation methods

Use of ShareSDK features

1. Share code call

After adding the configuration, you can call authorization, data acquisition, sharing and other operations, such as one click sharing code:

 
  //java
  private void showShare() {
     OnekeyShare oks = new OnekeyShare();
     // Title title, wechat, QQ, QQ space and other platforms
     oks.setTitle(getString(R.string.share));
     // titleUrl QQ and QQ space jump links
     oks.setTitleUrl("http://sharesdk.cn");
     // Text is shared text, which is required by all platforms
     oks.setText("I'm sharing text");
     // imagePath is the local path of the picture. Make sure the picture exists under the SDcard
     oks.setImagePath("/sdcard/test.jpg");
     // url is used in wechat, Facebook and other platforms
     oks.setUrl("http://sharesdk.cn");
    // Launch sharing GUI
    oks.show(this);
  }

Tiktok: the shared configuration of the voice is required.

Tiktok tiktok will be left behind by shaking or logon. You need to configure the value of callbackAct attribute to the full path of the interface you need to return, and you can successfully return.

Douyin {
                appKey "aw9ivykfjvi4hpwo"
                appSecret "42b4caa6bda60bd49f05f06d0a4956e1"
                callbackAct "com.mob.demo.TestActivity"
                enable true
            }

 

2. Third party login code call

//java

Platform plat = ShareSDK.getPlatform(QQ.NAME);
//Remove the authorization status and local cache. The next authorization will be re authorized
plat.removeAccount(true); 
//SSO authorization. Pass false. The default is client authorization
plat.SSOSetting(false); 
//Authorized callback listening, listening to three statuses: oncomplete, onerror and oncancel
plat.setPlatformActionListener(platformActionListener);
//Jitter login adaptation tiktok 9 Android
ShareSDK.setActivity(MainActivity.this);
//Data should not function, mainly reflected in the fact that the authorization interface will not appear repeatedly
plat.showUser(null);

4, Obfuscation settings

The ShareSDK has been obfuscated. If it is obfuscated again, it will cause unexpected errors. Please add the following configuration in your obfuscation script to skip the obfuscation of ShareSDK:

-keep class cn.sharesdk.**{*;}
-keep class com.sina.**{*;}
-keep class com.mob.**{*;}
-keep class com.bytedance.**{*;}
-dontwarn cn.sharesdk.**
-dontwarn com.sina.**
-dontwarn com.mob.**

For the mainstream andRes example: white list settings are as follows

andResGuard {
    whiteList = [              
        "R.layout.mob_authorize_*",
        "R.drawable.mobcommon_authorize_*",
        "R.drawable.ssdk_*",
        "R.drawable.ssdk_oks_*",
        "R.string.ssdk_oks_*",
        "R.string.ssdk_*",
        "R.style.mobcommon_*",  
        "R.ssdk_strings.*",
        "R.string.mobdemo_authorize_*",
    ]
}

Note: if the files under assets are confused, ShareSDK.xml also needs to be filtered.

5, Precautions

  1. The OnekeyShare library will be added by default in the ShareSDK. If you don't need this library, you can turn off OnekeyShare by setting "gui false" under the ShareSDK

  2. MobSDK provides the latest version of integration for ShareSDK by default. If you want to lock a version, you can set "version" under ShareSDK to fix this version

  3. If the module using MobSDK will be dependent by other modules, please make sure that the module relying on it also introduces the MobSDK plug-in, or add it to the gradle of this module:

     repositories {
         jcenter()
     }

6, Optional permission description

<!-- Optional permission description-->
android.permission.READ_PHONE_STATE    Read device ID

android.permission.WRITE_EXTERNAL_STORAGE    For caching shared pictures log Log and device identification, and use of file locks

android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_COARSE_LOCATION    For sharing SDK Display of regional analysis function in management background

Note: remove the optional permission method of automatic loading of Gradle: add the following configuration in the build.gradle file of module module

 permissions {
         exclude "Permissions to be removed 1", "Permissions to be removed 2"
     }

//For example, if you need to remove the "Android. Permission. Read" phone "state permission, add the following configuration directly,
    MobSDK {
    appKey "1ea..."
    appSecret "3ad..."

    ShareSDK { ... }

    permissions {
        exclude "android.permission.GET_ACCOUNTS",
    }
}
Published 7 original articles, won praise 7, visited 7310
Private letter follow

Keywords: Gradle SDK Android xml

Added by warpoet on Tue, 10 Mar 2020 10:40:30 +0200