0

I'm new to Twitter4R and Ruby on Rails. I'm using Ruby 1.9.2, Rails 3.1 and Twitter4R v0.7.0.

I'm trying to get my friends list from Twitter.

twitter = Twitter::Client.new(oauth_access: { key: token, secret: token_secret})

#these lines works fine.
twitter.status(:post, "POST TEST!!!")
twitter.friend(:add, "xxxx_jp")

#this line will cause ForbiddenError
friends = twitter.my(:friends)

I've checked the following site for information.

http://twitter4r.rubyforge.org/rdoc/Twitter/Client.html

Update

I now added config/initializers/twitter4r.rb:

require 'twitter'

Twitter::Client.configure do |config|
    config.oauth_consumer_token = consumer_key
    config.oauth_consumer_secret = consumer_secret
end

When debugging, I see the consumer_key and consumer_secret in Twitter::Consumer on debug window. But methods that require authentication like my(:friends) do not work.

How do I avoid the ForbiddenError?

tajihiro
  • 2,293
  • 7
  • 39
  • 60

1 Answers1

0

That looks like the authentication in Twitter::Client.new didn't actually work. Here's a presentation on OAuth by Twitter4R's creator Susan Potter:

http://www.slideshare.net/mbbx6spp/twitter4r-oauth

Michael Kohl
  • 66,324
  • 14
  • 138
  • 158
  • Thank you for your quick reply. I tried other methods like "status" or "timeline_for" which works without problem. But the method "my(:friends)" which I need does not work. I get dynamically twitter token and token secret from database. So I need to find out how configure Twitter::client. Anyway Thank you for your good advice. I will check the site. – tajihiro Jan 18 '12 at 09:14
  • I still stuck in. There is no way. (-_-;) – tajihiro Jan 19 '12 at 13:46