I am trying to pull tiktok data from the TikTok AP, and I am experiencing two problems currently:
1. I am having the error message: 'Timestamp has expired' even though I just renewed a new authentication code. I tried generating a timestamp dynamically to avoid this error but it is not working.
var timestamp = Math.floor(Date.now() / 1000).toString(); // Generate timestamp in seconds
2. I'm not sure if I am meeting the timestamp format requirements of the TikTok API and I don't know where to find this format as well.
If anyone could provide some advice on the above 2 points it would help a lot! Posting my code below for reference
function getToken() {
try {
var url = 'https://business-api.tiktok.com/open_api/v1.3/oauth2/creator_token/?business=tt_user';
var clientId = '';
var clientSecret = '';
var authCode = '';
//var timestamp = Math.floor(Date.now() / 1000).toString(); // Generate timestamp in seconds
var options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
//'Timestamp': timestamp
},
payload: JSON.stringify({
"business": "tt_user",
"client_id": clientId,
"client_secret": clientSecret,
"grant_type": "authorization_code",
"auth_code": authCode,
})
};
const response = UrlFetchApp.fetch(url, options);
const responseData = response.getContentText();
const dateHeader = response.getHeaders()['Date'];
const data = JSON.parse(responseData);
}
If there are any fundamental issues with the base code, I would love some feedback.