-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting "Bad request" when trying to post a tweet [nodejs] #75
Comments
Have you tried using a previous version of got? see: #76 I also suggest you check |
I did try to run this code and found that it did not work. The error I got was this: Instead change the require of index.js in /testwit/example2.js to a dynamic import() which is available in all CommonJS modules.
code: 'ERR_REQUIRE_ESM' Made these changes to the declarations at the top of the file and added "type":"module" to the package.json and it worked successfully: const readline = rl.createInterface({ @SamaaElKomy, I think it might be something with your keys as to why you got that particular error. |
|
I'm exploring the Twitter API integrated with Nodejs, currently trying to post a tweet using the example provided "Twitter-API-v2-sample-code/Manage-Tweets/create_tweet.js" but getting error "Bad request".
I only changed the consumer_key and consumer_secret with mine.
To Reproduce
Expected behavior
get the "Hello World" tweet posted successfully.
Output
GotError [HTTPError]: Response code 400 (Bad Request)
at EventEmitter. (/Users/samaael-komy/IBM Unify LC2/git/Emma-General-BE/node_modules/got/source/as-promise.js:74:19)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
host: 'api.twitter.com',
hostname: 'api.twitter.com',
method: 'POST',
path: '/2/tweets',
socketPath: undefined,
protocol: 'https:',
url: 'https://api.twitter.com/2/tweets',
gotOptions: {
path: '/2/tweets',
protocol: 'https:',
slashes: true,
auth: null,
host: 'api.twitter.com',
port: null,
hostname: 'api.twitter.com',
hash: null,
search: null,
query: null,
pathname: '/2/tweets',
href: 'https://api.twitter.com/2/tweets',
retry: {
retries: [Function (anonymous)],
methods: [Set],
statusCodes: [Set],
errorCodes: [Set]
},
headers: {
'user-agent': 'v2CreateTweetJS',
authorization: 'OAuth oauth_consumer_key="XXX", oauth_nonce="XXX", oauth_signature="XXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1642421266", oauth_token="XXX", oauth_version="1.0"',
'content-type': 'application/json',
accept: 'application/json',
'accept-encoding': 'gzip, deflate'
},
hooks: {
beforeRequest: [],
beforeRedirect: [],
beforeRetry: [],
afterResponse: [],
beforeError: [],
init: []
},
decompress: true,
throwHttpErrors: true,
followRedirect: true,
stream: false,
form: false,
json: { text: 'Hello world!' },
cache: false,
useElectronNet: false,
responseType: 'json',
method: 'POST'
},
statusCode: 400,
statusMessage: 'Bad Request',
headers: {
date: 'Mon, 17 Jan 2022 12:07:47 UTC',
server: 'tsa_f',
'set-cookie': [
'guest_id_marketing=XXX; Max-Age=63072000; Expires=Wed, 17 Jan 2024 12:07:47 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None',
'guest_id_ads=XXX; Max-Age=63072000; Expires=Wed, 17 Jan 2024 12:07:47 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None',
'personalization_id="XXX"; Max-Age=63072000; Expires=Wed, 17 Jan 2024 12:07:47 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None',
'guest_id=XXX; Max-Age=63072000; Expires=Wed, 17 Jan 2024 12:07:47 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None'
],
'api-version': '2.34',
'content-type': 'application/json; charset=utf-8',
'cache-control': 'no-cache, no-store, max-age=0',
'content-length': '187',
'x-access-level': 'read-write',
'x-frame-options': 'SAMEORIGIN',
'content-encoding': 'gzip',
'x-xss-protection': '0',
'x-rate-limit-limit': '200',
'x-rate-limit-reset': '1642421945',
'content-disposition': 'attachment; filename=json.json',
'x-content-type-options': 'nosniff',
'x-rate-limit-remaining': '197',
'strict-transport-security': 'max-age=631138519',
'x-response-time': '147',
'x-connection-hash': '2863900f313c672dd21c6ea0b1ba9b1f80b4ef8de9bc20aa2d5bfaa350f10016',
connection: 'close'
},
body: {
errors: [ [Object] ],
title: 'Invalid Request',
detail: 'One or more parameters to your request was invalid.',
type: 'https://api.twitter.com/2/problems/invalid-request'
}
}
The text was updated successfully, but these errors were encountered: