Twitter ::错误::在HomeController #index中未经授权

时间:2014-03-13 18:12:22

标签: ruby-on-rails ruby twitter

我在ruby中构建应用程序,我想要抓取我的粉丝。它一直告诉我:

Twitter::Error::Unauthorized in HomeController#index 
Could not authenticate you

这是我的代码:

client = Twitter::REST::Client.new do |config|
config.consumer_key        = "ONJKJHkWOD3ZFhjrVpx3Rw"
config.consumer_secret     = "myTVu2slmYfPcToNOfQb8HV4ECciAeCAor0VPD37Sc"
config.access_token        = "225985017-UjKFFh7fSQPSnKQWRM63wxXzW2ufu8g8z5RjLcNt"
config.access_token_secret = "WRQE66s4ez9mCVuwXzljaHnK9YvRecnPpfaZIlolAKFeN"
end

myfile = File.new("write.txt", "w")

count=0
cursor1=-1

while (cursor1 != 0) do
@followers =client.followers("riyadcarioca","cursor"=>"#{cursor1}")
cursor1=@followers.next_cursor
users=@followers.users
puts count
 users.each do |follower|
   count+=1
    myfile.puts "\"#{count}\",\"#{follower.name}\",\"#{follower.screen_name}\",\"#   {follower.url}\",\"#{follower.followers_count}\",\"#{follower.location}\",\"#{follower.created_at}\",\"#{follower.description}\",\"#{follower.friends_count}\",\"#{follower.lang}\",\"#{follower.time_zone}\",\"#{follower.verified}\""
 end
 sleep(5)
end

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

  1. 请勿在此处写下您的oauth凭据,以便人们可以查看有关您帐户的所有信息,包括推文,私人信息,(取决于您的权限)等等。

  2. 尝试重新生成您的访问令牌。

  3. 有时,当您从开发应用页面生成帐户令牌时,Twitter需要时间来更新您的帐户令牌,请查看令牌是否未更改。