Вопрос

I'm trying to connect to Twitter's REST API using application-only authentication. I get the bearer token, but the GET request doesn't work.

token = TOKEN
response = RestClient.get "https://api.twitter.com/1.1/followers/ids.json?screen_name=twitter", {headers: {'Authorization' => "Bearer #{token}"}}

Am I doing something incorrect with rest-client?

Это было полезно?

Решение

You don't need the "headers"-key. Since the hash after the URL is for headers your request will contain a header with the name "headers" rather than "Authoriziation".

It should work by just removing "headers":

RestClient.get "https://api.twitter.com/1.1/followers/ids.json?screen_name=twitter", {'Authorization' => "Bearer #{token}"} 
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top