Sharing on Android

Overview

This guide details how to enable sharing from your app to TikTok. After sharing successfully to TikTok, users will see your app's name in TikTok feed.

Note: The minimum TikTok version supporting sharing is 11.3.0.

Prerequisites

Before you can share to TikTok from your App, make sure you have obtained a Client Key from TikTok and installed the TikTok SDK to your Android project. For details on these requirements, see Getting started.

Detailed Steps

Edit your Application

First you need to initialize TikTokOpenApiFactory by using client key in your custom Application.

  @Override
public void onCreate() {
    super.onCreate();
    String clientkey = "[CLIENT_KEY]";
    TikTokOpenApiFactory.init(new TikTokOpenConfig(clientkey));
}

Edit Your Manifest

  1. Open the /app/manifest/AndroidManifest.xml file.
  2. Register TikTokEntryActivity for receiving callbacks in Manifest. If you have customized an activity to receive callbacks, you may skip this step.
//If you have customized activity to receive callnacks,you can skip the step
<activity
    android:name=".tiktokapi.TikTokEntryActivity"
    android:exported="true">
</activity>

Send Share Request

  1. Create a TiktokOpenApi to send share request.
  2. Build share content for images/videos into the TikTokMediaContent model.
  3. Create Share.Request instance and set required parameters: request.mMediaContent = [TikTokMediaContent].
  4. Call method Share() in TiktokOpenApi .
//1.create TiktokOpenApi
TiktokOpenApi tiktokOpenApi= TikTokOpenApiFactory.create(this);

Share.Request request = new Share.Request();
//initialize the resource path, please provide absolute path
ArrayList<String> mUri = new ArrayList<>();
mUri.add ...

//2.build share content for photos/videos into TikTokMediaContent
  VideoObject videoObject = new VideoObject();
  videoObject.mVideoPaths = mUri;
  MediaContent content = new MediaContent();
  content.mMediaObject = videoObject;
//3.set required parameters
  request.mMediaContent = content;

// or share multi-picture,here the size of mUri must >=2
   ImageObject imageObject = new ImageObject();
   imageObject.mImagePaths = mUri;
   MediaContent mediaContent = new MediaContent();
   mediaContent.mMediaObject = imageObject;
   request.mMediaContent = mediaContent;


//4.start share
tiktokOpenApi.share(request);

After a successful sharing session, a Dialog will prompt for the user to choose Back to your App or Stay in TikTok.

If you want to receive callbacks when people stay in TikTok , please register to receive a broadcast :

public static final String ACTION_STAY_IN_TT = "com.aweme.opensdk.action.stay.in.dy";

Parameters in Share.Request

ParameterUsage
mMediaContentYou can build share content for videos or photos using following models:
1.multi-Image: see ImageObjectmodel .
Note: The size of Images must more than one and up to 12.
2.single-video\multi-video: see VideoObjectmodel.
Then assign required parameter as request.mMediaContent = [MediaContent];
callerLocalEntrySet customized callback Activity by using request.callerLocalEntry = "com.xxx.xxx...activity"; If this parameter is not set, TikTok will callback TikTokEntryActivity in default.

Receive Callbacks

We provides two ways for you to receive the callback data from TikTok.

  1. Create new activity named "TikTokEntryActivity" in your app and implement TikTokApiEventHandler interface. Note: The path of the activity should be your "package name" + .tiktokapi.TikTokEntryActivity. For example, "com.tiktok.opensdk.tiktokapi.TikTokEntryActivity".

    The following example shows how to use the TikTokEntryActivity to receive the callback data.

    class TikTokEntryActivity extends Activity implements TikTokApiEventHandler {
    
       TiktokOpenApi ttOpenApi;
       @Override
       public void onCreate(@Nullable Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           ttOpenApi= TikTokOpenApiFactory.create(this);
           ttOpenApi.handleIntent(getIntent(),this); // receive and parse callback
       }
       @Override
       public void onReq(BaseReq req) {
       }
       @Override
       public void onResp(BaseResp resp) {
           if (resp.getType() == TikTokConstants.ModeType.SHARE_CONTENT_TO_TT_RESP)  {
               Share.Response response = (Share.Response) resp;
               Toast.makeText(this, " code:" + response.errorCode + " errorMessage:" + response.errorMsg, Toast.LENGTH_SHORT).show();
           }
       }
       @Override
       public void onErrorIntent(@Nullable Intent intent) {
           Toast.makeText(this, "Intent Error", Toast.LENGTH_LONG).show();
       }
    }
  2. You can also customize your own activity to receive the callback; just implement the interface IApiEventHandler and set your activity path by using parameter "callerLocalEntry".

// request.callerLocalEntry = "com.xxx.xxx...activity";

In the table below, each row represents error code. For further information please see the CommonConstants.

ErrorCodeDescription
0Success
-1Unknown error
-2User cancelled
-3Send failed
-4AuthDenied
-5Unsupported

If the error code does not make it easy for you to locate a specific error, you can use 'response.subErrorCode` for detail message. SDK version need 0.0.1.5 or higher and tiktok version need 14.4.0 or higher.

response.subErrorCodeDescription
20002Params parsing error, media resource type difference you pass
20003Not enough permissions to operation.
20004User not login
20005TikTok has no album permissions
20006TikTok Network error
20007Video length doesn't meet requirements
20008Photo doesn't meet requirements
20010Processing photo resources faild
20011Video resolution doesn't meet requirements
20012Video format is not supported
20013Sharing canceled
20015Users store shared content for draft or user accounts are not allowed to post videos
22001Unsupported resolution

Requirements for Media

  • For Video:
    • Minimum video duration must be 3 seconds
    • Supported video media type: .mp4
    • The Minimum of the frame size should be no more than 1100
  • For multi-Video:
    • The number of Videos can be no more than 12.
  • For multi-Image:
    • The number of images should be more than 1 and up to 12.
  • Videos cannot contain brand logos or watermarks. Violating this guideline will lead to videos being deleted or accounts being banned. Make sure your applications share content without watermarks or brand logos.

When you upgrade sdk to version 0.0.2.0,there are some changes you need to make.

How to integrate?

 dependencies {

        implementation 'com.bytedance.ies.ugc.aweme:opensdk-oversea-external:0.0.2.0'
         implementation 'com.bytedance.ies.ugc.aweme:opensdk-common:0.0.2.0'
    }

Compared to the old version of the SDK, the difference is the new SDK needs to integrate two libraries.

the class name of these classes have been changed, you need to change you code.

BeforeAfter
TikTokConstantsCommonConstants
TikTokApiEventHandlerIApiEventHandler
TikTokImageObjectImageObject
TikTokMediaContentMediaContent
TikTokVideoObjectVideoObject
TikTokMicroAppInfoMicroAppInfo

the package name of these classes have been changed, you need to reimport these classes

Class NamePackageName BeforePackageName After
TikTokOpenApiFactorycom.bytedance.sdk.open.awemecom.bytedance.sdk.open.tiktok.api
TikTokOpenApicom.bytedance.sdk.open.aweme.apicom.bytedance.sdk.open.tiktok.api
TikTokOpenConfigcom.bytedance.sdk.open.awemecom.bytedance.sdk.open.tiktok