400 On twitter.accountsAndUsers.accountUpdateProfileBanner()
See original GitHub issueDescribe the bug
As per the documentation of Twitter and twitter-api-client
, here is the code I’ve written that should update an account’s cover image 👇
const { default: TwitterClient } = require('twitter-api-client')
const fs = require('fs')
const twitter = new TwitterClient({
apiKey: '[API key]',
apiSecret: '[API secret]',
accessToken: '[access token]',
accessTokenSecret: '[access token secret]'
})
const set = async () => {
try {
const data = await twitter.accountsAndUsers.accountUpdateProfileBanner({
banner: fs.readFileSync('cover.jpg', { encoding: 'base64' })
})
console.log(data)
} catch (e) {
console.log(e)
}
}
set()
This results in 👇
{ statusCode: 400, data: '' }
and does not update the cover image of the authorized user. A quick note: The import is wrapped in a default
, which requires the usage of this ☝️ ugly syntax. Tried on JavaScript CommonJS and JavaScript ECMAScript Modules 🙂
To reproduce
Steps to reproduce the behavior:
- Copy the above code.
- Install credentials
- Have an image on the same directory named
cover.jpg
- Run the script.
Expected behavior
An updated cover image with a response of statusCode
of 200 or 201 with data
set to an empty string.
Package Manager:
Yarn: v1.22.5
Node.js: v15.0.1
Additional context
According to the documentation, on Twitter, the field banner
should be sent as a URL query parameter. But since a banner is usually a big file (relatively) it’s a bad practice to send it through URL query parameters.
Hence Twitter has updated to use x-www-form-urlencoded
(POST body) and that isn’t updated in their docs. Thanks, @Silind for making this module and I am 🙂 happy to give more info.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11
@vasanthdeveloper @pbteja1998 Fixed in version 1.1.1 🙌 Thanks a lot for your help, guys!
This is working for me in
postman
. But when tried to update it using this package, I am getting{statusCode: 431, data: ''}
, not 400.