Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAsterisks not encoded properly and result in error 32 "Could not authenticate you." #677
Comments
This comment has been minimized.
This comment has been minimized.
geori
commented
Jun 25, 2015
|
I'm having the same issue when posting @ or # in my search terms. I can't figure out where the conflict is, so I had to revert to 5.13.0 for my app to run properly. |
This comment has been minimized.
This comment has been minimized.
iandawg
commented
Nov 12, 2015
|
I've found that the same results occur using the https://dev.twitter.com/rest/tools/console. This seems to be an issue with the API, not with the gem. Any thoughts? |
This comment has been minimized.
This comment has been minimized.
dredenba
commented
Nov 2, 2016
|
Is there a work around for this? I thought I would be able to URL encode it manually if this gem doesn't do it but I don't get |
This comment has been minimized.
This comment has been minimized.
renatolond
commented
Sep 14, 2017
|
Sorry to re-raise this topic, but I'm getting the same on master. I am going around temporarily by replacing asterisk by *. I also tried what dredenba suggested of using the url encoded version and it does not work. |
This comment has been minimized.
This comment has been minimized.
alzeih
commented
Jan 27, 2018
|
I think I've figured out the cause of "Could not authenticate you" with https://github.com/sferik/twitter/blob/master/lib/twitter/rest/request.rb#L28 contains a call to @headers = Twitter::Headers.new(@client, @request_method, @uri, options).request_headersThis creates the oauth http headers, which signs the contents of the request, including the options. When the request is sent response = http_client.headers(@headers).public_send(@request_method, @uri.to_s, options_key => @options)the http library encodes the form data, which is fine in most cases, but with Since the request is now different, the twitter api rejects the request with a 401 Unauthorized. |
This comment has been minimized.
This comment has been minimized.
alzeih
commented
Jan 27, 2018
|
Actually, after reading #888, it's the other way around, it's not being encoded. It seems related to httprb/http#449 , which suggests a workaround. This patch works for me.
|
This comment has been minimized.
This comment has been minimized.
CedricBm
commented
Jan 29, 2018
|
Interesting patch @alzeih. However, this passes the tweet body into the URL as a GET parameter. So there are chances that we receive a |
This comment has been minimized.
This comment has been minimized.
alzeih
commented
Jan 29, 2018
|
@CedricBm it also doesn't work with image uploads - although not because of length, but due to how |
This comment has been minimized.
This comment has been minimized.
christianstanfield
commented
Mar 6, 2018
•
|
I'm also running into the same issue and can confirm that |
This comment has been minimized.
This comment has been minimized.
|
Hi, The 2.1.1 version of It allows to override the The following snippet overrides the encoding to act like the require "uri"
# The encoder method of the http gem needs to be overriden because of the twitter gem.
# Without that, there's an incompatibility between the simple_oauth gem which encodes asterisks and the http one which does not.
# Cf. https://github.com/httprb/form_data/issues/22 and https://github.com/sferik/twitter/issues/677
HTTP::FormData::Urlencoded.encoder = lambda do |enum|
unescaped_chars = /[^a-z0-9\-\.\_\~]/i
enum.map do |k, v|
if v.nil?
::URI::DEFAULT_PARSER.escape(k.to_s, unescaped_chars)
elsif v.respond_to?(:to_ary)
v.to_ary.map do |w|
str = ::URI::DEFAULT_PARSER.escape(k.to_s, unescaped_chars)
unless w.nil?
str << '='
str << ::URI::DEFAULT_PARSER.escape(w.to_s, unescaped_chars)
end
end.join('&')
else
str = ::URI::DEFAULT_PARSER.escape(k.to_s, unescaped_chars)
str << '='
str << ::URI::DEFAULT_PARSER.escape(v.to_s, unescaped_chars)
end
end.join('&')
endIt's been a few weeks we're using this method and it seems fine so far. Be careful though, it can have some side effects if some of the other gems you're using depend on |
FabienChaynes
referenced this issue
Jun 26, 2018
Closed
Unauthorized error when sending a tweet with an asterisk in 6.2.0 #888
renatolond
referenced this issue
Oct 10, 2018
Open
Statuses crossposted from Mastodon to Twitter use full-width asterisks #134
summera
referenced this issue
Oct 22, 2018
Closed
Asterisk character (*) counted incorrectly by JS library #269
This comment has been minimized.
This comment has been minimized.
kieraneglin
commented
Nov 29, 2018
|
Reviving this one to say it's still affecting the latest version |
jeremyhaile commentedApr 6, 2015
Twitter-text (1.11.0) says that tweets with asterisks are valid. And I am also allowed to post them to Twitter directly. However, when posted through the Twitter gem (6.0.0) I receive the error: "Could not authenticate you." (code 32)
This forum post indicates that asterisks need to be URL encoded to be valid, so shouldn't the Twitter gem be handling this for me?
https://twittercommunity.com/t/asterisk/6343