Open Mubtasimf443 opened 1 month ago
import { TWITER_USER_ACCESS_TOKEN, TWITER_USER_ACCESS_TOKEN_SECRET, TWITTER_APP_KEY, TWITTER_APP_SECRET } from "./_lib/utils/env.js"; import { TwitterApi } from "twitter-api-v2"; import path from 'path' import {fileURLToPath} from 'url'; let Client =new TwitterApi({ appKey:TWITTER_APP_KEY , appSecret:TWITTER_APP_SECRET, accessSecret :TWITER_USER_ACCESS_TOKEN_SECRET, accessToken:TWITER_USER_ACCESS_TOKEN }); (async function () { try { let mediaID =await Client.v1.uploadMedia(path.resolve(__dirname,'./public/img/event.jpg')); log('mediaID : '+mediaID) } catch (error) { log({error}) } })()
PS C:\git\Client Project\gojushinryo\sv> node s.js { error: ApiResponseError: Request failed with code 403 at RequestHandlerHelper.createResponseError (C:\git\Client Project\gojushinryo\sv\node_modules\twitter-api-v2\dist\cjs\client-mixins\request-handler.helper.js:104:16) at RequestHandlerHelper.onResponseEndHandler (C:\git\Client Project\gojushinryo\sv\node_modules\twitter-api-v2\dist\cjs\client-mixins\request-handler.helper.js:262:25) at IncomingMessage.emit (node:events:531:35) at endReadableNT (node:internal/streams/readable:1696:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { error: true, type: 'response', code: 403, headers: { perf: '7402827104', 'cache-control': 'no-cache, no-store, max-age=0', 'content-length': '0', 'x-transaction-id': 'c92a36dd0e0cd4da', 'x-response-time': '93', 'x-connection-hash': '0b1356a40d78ff449ec34c0617d026f07f45a597825625496583a8c38d039013', date: 'Mon, 21 Oct 2024 00:06:05 GMT', server: 'tsa_m' }, rateLimit: undefined, data: '' } } PS C:\git\Client Project\gojushinryo\sv>
I was expecting to see image id uploaded to twitter mediaID 29470463289469
I had not use 1 parametar on the api , that was command=INIT
command=INIT
the correct api is const uploadUrl = 'https://upload.twitter.com/1.1/media/upload.json?media_category=tweet_image&total_bytes='+size+'&command=INIT'
const uploadUrl = 'https://upload.twitter.com/1.1/media/upload.json?media_category=tweet_image&total_bytes='+size+'&command=INIT'
I am uplaoding an Image to twitter but I found 403 error
PS C:\git\Client Project\gojushinryo\sv> node s.js { error: ApiResponseError: Request failed with code 403 at RequestHandlerHelper.createResponseError (C:\git\Client Project\gojushinryo\sv\node_modules\twitter-api-v2\dist\cjs\client-mixins\request-handler.helper.js:104:16) at RequestHandlerHelper.onResponseEndHandler (C:\git\Client Project\gojushinryo\sv\node_modules\twitter-api-v2\dist\cjs\client-mixins\request-handler.helper.js:262:25) at IncomingMessage.emit (node:events:531:35) at endReadableNT (node:internal/streams/readable:1696:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { error: true, type: 'response', code: 403, headers: { perf: '7402827104', 'cache-control': 'no-cache, no-store, max-age=0', 'content-length': '0', 'x-transaction-id': 'c92a36dd0e0cd4da', 'x-response-time': '93', 'x-connection-hash': '0b1356a40d78ff449ec34c0617d026f07f45a597825625496583a8c38d039013', date: 'Mon, 21 Oct 2024 00:06:05 GMT', server: 'tsa_m' }, rateLimit: undefined, data: '' } } PS C:\git\Client Project\gojushinryo\sv>
I was expecting to see image id uploaded to twitter mediaID 29470463289469