Could not authenticate you on destroy_direct_message
GCorbel opened this issue · comments
I'm trying to destroy a direct message just with client.destroy_direct_message(123)
. It was working with Twitter 6.2.0 but not with the latest version. It produces the error Twitter::Error::Unauthorized: Could not authenticate you
.
I inspected a bit and
- Twitter::Rest::DirectMessages#destroy_direct_message, the value of
id
is "123" - normal - Twitter::Rest::Utils#perform_requests,
ids
is the hash{ id: 123 }
and an array is expected. - Twitter::Rest::Utils#perform_request,
options
is {:id=>[:id, 1825785544]}
The solution is probably to change Twitter::Rest::DirectMessages#destroy_direct_message
and give an array. What I don't understand (I didn't inspect deeply) is why specs are working.
Do you confirm there is a bug? I will open an MR for that.
Hello,
I'm having the same problem. I understand the PR has been merged, but it hasn't been released, right? (I'm using twitter (7.0.0) and I'm having the issue)
In case it helps,
here's evidence that the bug is present:
1] pry(#<Filter>)> id = msg.dig('id')
=> "1325608100544602111"
[2] pry(#<Filter>)> id = msg.dig('id').to_i
=> 1325608100544602111
[3] pry(#<Filter>)> @client.destroy_direct_message(id)
Twitter::Error::Unauthorized: Could not authenticate you.
from /home/developer/.rvm/gems/ruby-2.6.5/gems/twitter-7.0.0/lib/twitter/rest/request.rb:97:in `fail_or_return_response_body'
[4] pry(#<Filter>)> @client
=> #<Twitter::REST::Client:0x000055f98a109c88
@access_token="xxx",
...
@user_agent="TwitterRubyGem/7.0.0">
[5] pry(#<Filter>)> @client.class
=> Twitter::REST::Client
[6] pry(#<Filter>)> @client.settings # I have valid creds/tokens
=> #<Twitter::Settings:0x000055f98a155520
@attrs=
{:protected=>false,
...
If someone else is having this problem, I found a "hackish" way to get this done:
Twitter::REST::Request.new(@client, :delete, "/1.1/direct_messages/events/destroy.json?id=#{id}").perform