Twitter API - Ruby Twitter Gem

后端 未结 2 540
感情败类
感情败类 2021-01-27 09:36

How can I access Twitter::Cursor hash values returned by the Twitter API?

I am following the Jumpstartlab Microblogger tutorial for using the Twitter gem via the jumpsta

相关标签:
2条回答
  • 2021-01-27 10:25

    those answers didn't helped me to get the last message (maybe the API changed in the meantime), that's how I finally did it:

        def everyones_last_tweet
          puts "\n\n here are the latest tweets of your friends:"
          friends = @client.friends.collect { |f| @client.user(f) }
          friends.each do |friend|
            puts "\n\n#{friend.screen_name} wrote: \n\t #{friend.status.text}"
          end
        return ""
    end
    

    I'm not happy with that return string though

    0 讨论(0)
  • 2021-01-27 10:32

    Access the 'friends' object in the same way you accessed the 'followers' object earlier in the tutorial in order to get a list of your followers' screen names.

    To get an array of followers' screen names:

    screen_names = @client.followers.collect {|f| @client.user(f).screen_name }
    

    To get an array of friends' screen names:

    screen_names = @client.friends.collect {|f| @client.user(f).screen_name }
    

    To get the last tweet of a friend, you can use the object_id's you posted above, as:

    last_tweet = @client.user(object_id).status.tweet
    

    I hope this helps. I was caught on this issue for a while too.

    0 讨论(0)
提交回复
热议问题