Twitter API - Ruby Twitter Gem [英] Twitter API - Ruby Twitter Gem

查看:142
本文介绍了Twitter API - Ruby Twitter Gem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我遵循Jumpstartlab Microblogger教程,通过使用Twitter gem。 href =http://tutorials.jumpstartlab.com/projects/microblogger.html =nofollow> jumpstart_auth 宝石

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

我在迭代4步骤1中。我可以使用下面的代码返回一个朋友对象:

I am on iteration 4 step 1. I can return a friends object with the following code:

def friends_last_tweets
  friends = client.friends
  puts friends
end

=>    Twitter::Cursor:0x00000104051928

然而,示例账户'client'在这种情况下有两个'朋友'不只是一个,所以为什么它只返回一个对象?我想也许这个对象是数组或者所有的朋友相应的哈希值,因此使用 [] 来访问,但是这会返回未定义的Twitter方法: :光标。我在Twitter :: Cursor对象上运行每个,并返回两个fixnums:

However, the example account, 'client' in this case, has two 'friends' not just one so why does it only return one object? I thought maybe that object is the array or arrays with all of the friends accordingly in hash values within, thus use [] to access, but this returns "undefined method for Twitter::Cursor". I run each on the Twitter::Cursor object and it returns two fixnums:

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

=> 18908095
108528349

所以这些数字肯定代表Twitter中的每个'朋友对象': :光标对象我认为。我需要访问该对象中的键/值对,但我尝试的哈希访问会导致未定义的方法或变量。

So surely these numbers must represent each 'friend object' within the Twitter::Cursor object me thinks. I need to access the key/value pairs within that object, yet my attempted hash accessing results in undefined method or variable.

如果版本问题相关,我使用Twitter5.11.0和Jumpstart_auth 0.6.0。

In case it's version issue related, I'm using Twitter5.11.0 and Jumpstart_auth 0.6.0.

推荐答案

访问'friends'对象的方式与访问'followers '的对象,以获得你的追随者的屏幕名称列表。

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.

要获得一组追随者的屏幕名称

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

获取朋友数组的屏幕姓名

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

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

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.

这篇关于Twitter API - Ruby Twitter Gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆