maz

maz

How To Make a Successful Post to Twitter/X Using Oauther

Anyone manage to successfully post a status to Twitter/X using their older Oauth 1.0a API? I tried oauther which seems to have lost it’s maintainer but it appears to still work, and I’m getting a 403 when attempting to POST to statuses/update

I’ve confirmed that I have Read, Write and DM permissions enabled, have indicated that my app is a bot with a backend and then after that I revoked and regenerated the consumer keys and access keys. This is from advisement from various posts on X’s development community.

Or is there a better tool out there now?

here is my iex log:

iex(14)> creds = OAuther.credentials(consumer_key: "my_consumer_key", consumer_secret: "my_consumer_secret", token: "my_token", token_secret: "my_token_secret")
%OAuther.Credentials{
  consumer_key: "my_consumer_key",
  consumer_secret: "my_consumer_secret",
  token: "my_token",
  token_secret: "my_token_secret",
  method: :hmac_sha1
}

## Should I use "post" here?

iex(15)> params = OAuther.sign("post", "https://api.twitter.com/1.1/statuses/update.json", [{"status", "a test status"}], creds)
[
  {"oauth_signature", "0ii5DrkWeIDx39KN2OD20AospOE="},
  {"oauth_consumer_key", "my_consumer_key"},
  {"oauth_nonce", "dNU7BJgpree9ym4F43ffMpiFHRnvI0Tp"},
  {"oauth_signature_method", "HMAC-SHA1"},
  {"oauth_timestamp", 1706679860},
  {"oauth_version", "1.0"},
  {"oauth_token", "my_token"},
  {"status", "a test status"}
]
iex(16)> {header, req_params} = OAuther.header(params)
{{"Authorization",
  "OAuth oauth_signature=\"0ii5DrkWeIDx39KN2OD20AospOE%3D\", oauth_consumer_key=\"my_consumer_key\", oauth_nonce=\"dNU7BJgpree9ym4F43ffMpiFHRnvI0Tp\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1706679860\", oauth_version=\"1.0\", oauth_token=\"my_token\""},
 [{"status", "a test status"}]}
iex(17)> :hackney.post("https://api.twitter.com/1.1/statuses/update.json", [header], {:form, req_params})

## 403 error

{:ok, 403,
 [
   {"perf", "7469935968"},
   {"content-type", "application/json;charset=utf-8"},
   {"cache-control", "no-cache, no-store, max-age=0"},
   {"content-length", "311"},
   {"x-transaction-id", "80f718cad47dede4"},
   {"x-response-time", "3"},
   {"x-connection-hash",
    "8ebe492896cb27c4fcdfa8c34cfc739ac96a5a52138223760234f05add6d8466"},
   {"date", "Wed, 31 Jan 2024 05:44:31 GMT"},
   {"server", "tsa_b"}
 ], #Reference<0.2839908345.1444675585.60472>}
iex(18)> 

Regards,
Michael

Marked As Solved

maz

maz

Same credentials work with the python tweepy library. The tweepy library also requires the Bearer Token. So it appears you can no longer use Oauther with Twitter/X.

Where Next?

Popular in Questions Top

New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New

Other popular topics Top

New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31013 112
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement