Skip to content

Code example for uploading avatar / profile banner? (v1.1) #48

@marckohlbrugge

Description

@marckohlbrugge

X API 2.0 does not support uploading an avatar or profile banner, but 1.1 does:
https://developer.x.com/en/docs/x-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_banner

I tried the following:

x_client = X::Client.new(base_url: "https://api.twitter.com/1.1/", **x_credentials)

x_client.post("account/update_profile_banner.json", {
  banner: Base64.encode64(File.read("test.png")),
}.to_json)

Which returns the following error:

banner parameter is missing. (X::BadRequest)

I also tried this:

x_client.post("account/update_profile_banner.json", {
  banner: Base64.encode64(File.binread("test.png")),
}.to_json, headers: {
  "Content-Type" => "application/json"
})

Which also returns:

banner parameter is missing. (X::BadRequest)

I also tried the following:

x_client.post("account/update_profile_banner.json?banner=#{Base64.encode64(File.read("test.png"))}")

Which returns:

Request-URI Too Large (X::HTTPError)

I also experimented with code found in #4 (comment) but didn't have any luck there either.


Would love a working code example for this. I expect that if we can make it work for the profile banner, we can use a similar approach for uploading avatars which might be a common request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions