Docs
Share Kit for Android
This guide demonstrates how to enable sharing videos and images from your app to TikTok.
Prerequisites
Before sharing videos to TikTok from your app, you must complete all the steps in Android Quickstart.
Obtain the client_key
located in the Appdetails section of your app on the TikTok for Developers website. Then add Share Kit and Login Kit to your app by navigating to the Manage apps page, and clicking + Add products.
Send a share request
- Create a
ShareApi
to send a share request. - Build share content for images and videos into the
MediaContent
model. - Create a
ShareRequest
object and set the required parameters. You can use theshareFormat
field in the share request object to share images or videos to TikTok in different formats. Format.DEFAULT
: The default share format. This format allows your app to share images or videos, as is, to TikTok.Format.GREEN_SCREEN
: See Green Screen Kit for more details.- Call the
Share()
method inShareApi
.
/* Step 1 */
shareApi = ShareApi(
activity = [your_activity],
)
/* Step 2 */
val mediaContent = MediaContent(
mediaType = if (isSharingImage) MediaType.IMAGE else MediaType.VIDEO,
mediaPaths = mediaUrls, // a list of selected media paths
)
// use Share.Format.GREEN_SCREEN for green screen share and Share.Format.DEFAULT for default share
val shareFormat = shareFormat = if (greenScreenEnabled) {
Format.GREEN_SCREEN
} else {
Format.DEFAULT
}
/* Step 3 */
val request = ShareRequest(
clientKey = clientKey,
mediaContent = mediaContent,
shareFormat = shareFormat,
packageName = [package name of your activity which will receive share result intent from TikTok, e.g com.bytedance.sdk.demo.share],
resultActivityFullPath = [full class path of your activity which will receive share result intent from TikTok, e.g com.bytedance.sdk.demo.share.ShareActivity]
)
/* Step 4 */
shareApi.share(request);
If you want to share a file with the file:///
Uri
path, follow Android's FileProvider instruction to create content://
Uri
for the file first, and then share it with TikTok.
Make sure you also grant TikTok access permission to your content Uri:
context.grantUriPermission("com.zhiliaoapp.musically", your_content_uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
context.grantUriPermission("com.ss.android.ugc.trill", your_content_uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
After a successful sharing session, a dialog will prompt the user to either go back to their app or stay in TikTok.
If you want to receive callbacks when users stay in TikTok, register to receive a broadcast.
public static final String ACTION_STAY_IN_TT = "com.aweme.opensdk.action.stay.in.dy";
Receive callbacks
Provide the package name and the activity full path in the ShareRequest
and then the response will be sent to your activity.
Make sure you have set android:exported="true"
for your activity so that it can receive messages from sources outside its application.
<activity
android:name="You activity which is gonna receive the sharing result intent from TikTok"
....
android:exported="true">
</activity>
Parse ShareResponse
from intent
with ShareApi.getShareResponseFromIntent
.
shareApi.getShareResponseFromIntent(intent)?.let {
val isSuccess = it.isSuccess
val errorCode = it.errorCode
val subErrorCode = it.subErrorCode
val errorMsg = it.errorMsg
}
Requirements for media
- For video sharing:
- The minimum video duration is 3 seconds.
- The supported video media type is
.mp4
. - The maximum frame size is 1100 px.
- For multi-videos, the maximum number of videos is 35.
- For image sharing:
- The number of images should be more than 1 and up to 35.
- For green screen sharing:
- The number of images and videos should only be 1.
- You must be authorized to use any brand logos and watermarks. See TikTok Brand and Use Guidelines for more details.
Error handling
If you receive an error sharing response, refer to the table below for error handling and debugging.
Error Code | Sub Error Code | Error Message |
0 | 0 | Success. |
-1 | -1 | Unknown error. |
-3 | 20002 | Parameters parsing error. |
-3 | 10011 | App certificate does not match configurations。 |
-4 | 20005 | TikTok has no album permissions. |
-12 | 20006 | TikTok Network error. |
-5 | 20008 | Photo doesn't meet requirements. |
-5 | 20010 | Processing photo resources failed. |
-5 | 20012 | Video format is not supported. |
-2 | -2 | Sharing canceled. |
-4 | 20016 | Users store shared content for draft or user accounts are not allowed to post videos. |
-1 | -1 | Share Denied. |