Skip to content

Commit 9ed3560

Browse files
committed
Add example for uploading profile media
1 parent cfcbc0d commit 9ed3560

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

examples/upload_profile_media.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require "base64"
2+
require "uri"
3+
require "x"
4+
5+
x_credentials = {
6+
api_key: "INSERT YOUR X API KEY HERE",
7+
api_key_secret: "INSERT YOUR X API KEY SECRET HERE",
8+
access_token: "INSERT YOUR X ACCESS TOKEN HERE",
9+
access_token_secret: "INSERT YOUR X ACCESS TOKEN SECRET HERE"
10+
}
11+
12+
client = X::Client.new(base_url: "https://api.twitter.com/1.1/", **x_credentials)
13+
14+
avatar_path = "path/to/avatar.jpg"
15+
avatar_data = Base64.encode64(File.binread(avatar_path))
16+
avatar_body = URI.encode_www_form(image: avatar_data)
17+
client.post("account/update_profile_image.json", avatar_body, headers: {"Content-Type" => "application/x-www-form-urlencoded"})
18+
19+
banner_path = "path/to/banner.jpg"
20+
banner_data = Base64.encode64(File.binread(banner_path))
21+
banner_body = URI.encode_www_form(banner: banner_data)
22+
client.post("account/update_profile_banner.json", banner_body, headers: {"Content-Type" => "application/x-www-form-urlencoded"})

0 commit comments

Comments
 (0)