jootl
#1
Hello!
I’m using Twitter Bot API for a dotnet core project and when I call POST statuses/update with user mention, I have error 401 with code 32:
{
"errors": [
{
"code": 32,
"message": "Could not authenticate you."
}
]
}
If I’m using this endpoint without user mention, it’s working.
So now I’m using Postman with OAuth1.0 authentication to check the endpoint without my code and I have the same behavior.
I have same problem without in_reply_to_status_id . I also tried with %40 instead of @ but always error code 32 (no problem without user mention).
The endpoint GET account/verify_credentials returns me a 200 OK .
Any ideas?
This is most likely due to improper % encoding of the parameters / signature base string - both have to match: Creating a signature | Docs | Twitter Developer Platform
Also it could be the sorting order of parameters. Postman always seems to have problems like this - twurl is better for testing calls GitHub - twitter/twurl: OAuth-enabled curl for the Twitter API
jootl
#3
Thanks for the tip! It’s working with twurl.
So now, it’s still not working with my CSharp code. 
If I replace the @ by a +, it’s working (this scenario was not working with Postman).
In my signature construction I dont see anything wrong, but i’m sure there is.
I used this to build it.
My test message is Hello @my_user in reply to one of my tweet.
In first step I encode status like this:
in_reply_to_status_id=1247532209524756482&oauth_consumer_key=MYCONSUMERKEY&oauth_nonce=006fc214-d3d5-405f-9d92-f53c047e1451&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1590583063&oauth_token=MYAUTH-TOKEN&oauth_version=1.0&status=Hello%20%40my_user
When creating the signature base string, I get:
POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fupdate.json&in_reply_to_status_id%3D1247532209524756482%26oauth_consumer_key%3DMYCONSUMERKEY%26oauth_nonce%3D006fc214-d3d5-405f-9d92-f53c047e1451%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1590583063%26oauth_token%3DMYAUTH-TOKEN%26oauth_version%3D1.0%26status%3DHello%2520%2540my_user
And in last step, I get this header:
oauth_consumer_key="MYCONSUMERKEY", oauth_nonce="006fc214-d3d5-405f-9d92-f53c047e1451", oauth_signature="PWH8PzpBTkXroL5JgY%2B6e37K7t8%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1590583063", oauth_token="MYAUTH-TOKEN", oauth_version="1.0"
I percented encode every parameters.
I dont understand why only @ is not working.
PS: my code https://gist.github.com/jterral/431c1dc88a9e2f1abe42465e1d56669f
I don’t know C# to debug but another common problem to look for is double % encoding (encoding an already encoded thing)
I can’t speak to the C# code specifically, but I typically find that this workaround resolves the issues in Postman:
If you’re facing this issue for a POST request, you can use Body tab rather than Params tab.
- Disable all params in
Params tab
- Open
Body tab and click x-www-form-urlencoded then add params as needed
You could consider trying one of the existing C# libraries such as CoreTweet, LinqToTwitter or Tweetinvi these implement the OAuth piece for you.
system
Closed
#6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.