twitterapi-rubytwittergem

twitterapi-rubytwittergem,ruby,twitter,methods,hash,Ruby,Twitter,Methods,Hash,如何访问Twitter API返回的Twitter::Cursor哈希值 我正在学习JumpstartAB微博客教程,通过 我在迭代4步骤1中。我可以使用以下代码返回friends对象: def friends_last_tweets friends = client.friends puts friends end => Twitter::Cursor:0x00000104051928 但是,示例帐户“client”在本例中有两个“friends”,而不仅仅是一个,那么

如何访问Twitter API返回的Twitter::Cursor哈希值

我正在学习JumpstartAB微博客教程,通过

我在迭代4步骤1中。我可以使用以下代码返回friends对象:

def friends_last_tweets
  friends = client.friends
  puts friends
end

=>    Twitter::Cursor:0x00000104051928
但是,示例帐户“client”在本例中有两个“friends”,而不仅仅是一个,那么为什么它只返回一个对象呢?我认为可能该对象是一个或多个数组,其中的所有好友都相应地包含在哈希值中,因此使用
[]
进行访问,但这将返回“undefined method for Twitter::Cursor”。我在Twitter::Cursor对象上运行
每个
,它返回两个fixnums:

def friends_last_tweets
    friends = client.friends
    friends.each { |f| puts f }
end

=> 18908095
108528349
所以这些数字肯定代表了Twitter::Cursor对象中的每个“朋友对象”。我需要访问该对象中的键/值对,但尝试的哈希访问导致未定义的方法或变量


如果它与版本问题有关,我使用的是Twitter5.11.0和Jumpstart_auth 0.6.0。

访问“朋友”对象的方式与您在本教程前面访问“关注者”对象的方式相同,以便获得关注者的屏幕名称列表

要获取追随者的屏幕名称数组,请执行以下操作:

要获取朋友的屏幕名称数组,请执行以下操作:

要获取朋友的最后一条推文,您可以使用上面发布的对象id,如下所示:

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

我希望这有帮助。我也被这个问题困扰了一段时间。

这些答案并没有帮助我获得最后一条信息(可能API在此期间发生了变化),我最终就是这样做到的:

    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

我对返回的字符串不满意,不过

谢谢,我今天晚些时候会再次尝试。@user3346954你有没有把它用到可以获取ID和名称而不是hashtag响应的地方?我被卡住了:\
last_tweet = @client.user(object_id).status.tweet
    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