question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

400 On twitter.accountsAndUsers.accountUpdateProfileBanner()

See original GitHub issue

Describe 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:

  1. Copy the above code.
  2. Install credentials
  3. Have an image on the same directory named cover.jpg
  4. 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:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

4reactions
SimonHoibergcommented, Nov 6, 2020

@vasanthdeveloper @pbteja1998 Fixed in version 1.1.1 🙌 Thanks a lot for your help, guys!

1reaction
pbteja1998commented, Nov 6, 2020

This is working for me in postman. But when tried to update it using this package, I am getting {statusCode: 431, data: ''}, not 400.

Read more comments on GitHub >

github_iconTop Results From Across the Web

400 On twitter.accountsAndUsers.accountUpdateProfileBanner()
Steps to reproduce the behavior: Copy the above code. Install credentials; Have an image on the same directory named cover.jpg; Run the script....
Read more >
POST account/update_profile_banner | Docs - Twitter Developer
Uploads a profile banner on behalf of the authenticating user. More information about sizing variations can be found in User Profile Images and...
Read more >
Twitter API Response Codes & Error Support
Get Twitter API response codes and error support through Twitter Developer here. ... There was no new data to return. Troubleshooting tips. Code....
Read more >
POST friendships/create | Docs | Twitter Developer Platform
Allows the authenticating user to follow (friend) the user specified in the ID parameter. Returns the followed user when successful. Returns a string...
Read more >
GET users/show | Docs | Twitter Developer Platform
We recently released user lookup, a set of Twitter API v2 endpoints that have the same functionality as this one. The new version...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found