I'm sorry to hear you're encountering an error with your TikTok OAuth integration. The error message you're receiving, {"data":{"captcha":"","desc_url":"","description":"Illegal redirect link","error_code":10006},"message":"error"}, indicates an issue with the parameter in your OAuth request.
User
tiktok setup upload with sandbox upload credentials
Assistant
User
generate a url that will help me generate token
Assistant
To upload files to TikTok using their API, you can utilize the Content Posting API, which supports both video and photo uploads. Here's a step-by-step guide to help you through the process:
1. Prerequisites:
TikTok Developer Account: Ensure you have a registered app on the TikTok for Developers platform.
API Product Addition: Add the Content Posting API product to your app.
Scope Approval: Obtain approval for the video.upload scope and ensure the target TikTok user has authorized your app for this scope.
Access Token and Open ID: Acquire the access token and open ID of the TikTok user who authorized your app.
2. Uploading Videos:
You have two options to upload videos:
Option A: Uploading from a Local File
Initialize Video Upload:
Send a POST request to the /v2/post/publish/inbox/video/init/ endpoint with the following payload:
Ensure that the photo_images URLs are from a verified domain or URL prefix.
4. Additional Considerations:
Domain Verification: For PULL_FROM_URL uploads, verify your domain or URL prefix with TikTok.
Chunked Uploads: For large videos, consider uploading in chunks. Each chunk must be between 5 MB and 64 MB, except the final chunk, which can be up to 128 MB.
Rate Limits: Be aware of TikTok's rate limits to avoid request rejections.
For detailed information and code examples, refer to the TikTok Content Posting API Documentation.</total_byte_length></last_byte></upload_url></total_byte_length></last_byte></upload_url></total_number_of_chunks></chunk_size_in_bytes></video_size_in_bytes></total_number_of_chunks></chunk_size_in_bytes></video_size_in_bytes>
redirect_uri
Possible Causes and Solutions:
Mismatch Between Registered and Provided Redirect URIs:
Cause: The redirect_uri specified in your OAuth request doesn't exactly match the one registered in your TikTok Developer Portal.
Solution: Ensure that the redirect_uri in your OAuth request is identical to the one you've registered, including the protocol (https), domain, and path. For example, if you've registered https://zxcxc.com/tiktok/callback, your OAuth request should use the exact same URL.
Application Status:
Cause: Your TikTok application might still be in "Staging" mode.
Solution: Submit your application for review in the TikTok Developer Portal. Once approved and set to "Live in production," the OAuth flow should function correctly.
Redirect Domain Configuration:
Cause: The redirect_uri domain isn't listed in your application's "Redirect domain" settings.
Solution: In the TikTok Developer Portal, navigate to your application's settings and add zxcxc.com to the "Redirect domain" field. Note that TikTok requires the domain without the protocol and path.
Use of Ports in Redirect URI:
Cause: Including port numbers in the redirect_uri can cause errors.
Solution: Ensure that your redirect_uri doesn't include any port numbers. For instance, use https://zxcxc.com/tiktok/callback instead of https://zxcxc.com:8080/tiktok/callback.
Additional Considerations:
OAuth Version: TikTok has updated its OAuth endpoints. Ensure you're using the latest version as per their migration guidance.
Error Handling: Familiarize yourself with TikTok's OAuth error handling to better understand and troubleshoot potential issues.
By addressing these areas, you should be able to resolve the redirect_uri error and successfully integrate TikTok's OAuth into your application.
To set up and test content uploads to TikTok using the Sandbox environment, follow these steps:
In your developer dashboard, click on "Create App" and provide the necessary details such as the app name, description, and platform.
3. Add the Content Posting API Product:
Within your app's settings, navigate to the "Products" section.
Add the "Content Posting API" to your app.
4. Enable Sandbox Mode:
In your app's dashboard, toggle the environment to "Sandbox."
Click on "Create Sandbox," provide a name, and confirm.
You can choose to clone configurations from your production app or another sandbox.
5. Configure Redirect URI:
For the Login Kit, set the Redirect URI to match your application's callback URL.
Ensure this URI is consistent with the one registered in your app settings.
6. Add Target Users:
In the Sandbox settings, under "Target users," click "Add account."
Log in with a TikTok account to authorize it as a test user.
You can add up to 10 test accounts.
7. Obtain Access Token and Open ID:
Use the Login Kit to authenticate the test user and obtain the access token and open ID.
Ensure the video.upload scope is included during the authorization process.
8. Upload Content:
With the access token, you can now use the Content Posting API to upload videos or photos.
For videos, you can choose between:
File Upload: Upload a video file directly from your local storage.
Pull from URL: Provide a URL from which TikTok will fetch the video. Ensure the domain is verified.
For photos, provide URLs of the images from your verified domain.
9. Verify Uploads:
After uploading, check the status of your uploads using the publish_id returned in the API response.
In the Sandbox environment, content will be uploaded as drafts. Test users can log into their TikTok accounts to review and post the content.
Important Considerations:
Domain Verification: For the "Pull from URL" method, ensure that the domain or URL prefix is verified in your app settings.
Rate Limits: Be aware of TikTok's rate limits to avoid request rejections.
Sandbox Limitations: The Sandbox environment is designed for testing and may have limitations compared to the production environment.
By following these steps, you can effectively set up and test content uploads to TikTok using the Sandbox environment.
To generate a URL that facilitates obtaining an access token from TikTok, you'll need to construct an OAuth authorization URL. This URL directs users to TikTok's authorization page, where they can grant your application the necessary permissions. Here's how to create this URL:
1. Prerequisites:
TikTok Developer Account: Ensure you have a registered app on the TikTok for Developers platform.
Client Key: Obtain your app's client_key from the developer portal.
Redirect URI: Register a redirect URI in your app's settings. This is where users will be redirected after authorization.
2. Constructing the Authorization URL:
The base URL for TikTok's OAuth authorization is:
code
https://www.tiktok.com/v2/auth/authorize/
You'll need to append the following query parameters to this URL:
client_key: Your app's client key.
response_type: Set this to code.
scope: A comma-separated list of permissions your app requires. For example, user.info.basic,video.upload.
redirect_uri: The URI where users will be redirected after authorization. This must match the redirect URI registered in your app's settings.
state: A unique, non-guessable string to maintain the state between the request and callback. This helps prevent cross-site request forgery (CSRF) attacks.
After the user authorizes your app, TikTok will redirect them to your specified redirect_uri with the following query parameters:
code: The authorization code to be exchanged for an access token.
state: The state parameter you provided, which should be verified to prevent CSRF attacks.
5. Exchanging the Authorization Code for an Access Token:
To obtain the access token, make a POST request to TikTok's token endpoint:
code
https://open.tiktokapis.com/v2/oauth/token/
Include the following parameters in the request body:
client_key: Your app's client key.
client_secret: Your app's client secret.
code: The authorization code received from the redirect.
grant_type: Set this to authorization_code.
redirect_uri: The same redirect URI used in the authorization request.
For detailed information on managing user access tokens, refer to TikTok's Manage User Access Tokens documentation.
Note: Ensure that all parameters are correctly URL-encoded and that your app's settings in the TikTok Developer Portal match the values used in your requests.