ruby-on-rails-3.1 - 在 Twitter API 中使用 object.entities 的私有(private)方法错误

标签 ruby-on-rails-3.1 twitter private-methods

尝试在我的 twitter 提要 Controller 中调用 tweet.entities 时出现以下错误。

调用#Twitter::Status:0x94d4bf4 的私有(private)方法“实体”

我在代码中没有称为实体的方法,我什至进行了完整的文件搜索来检查。

我要么需要重命名对象的实体部分,要么以某种方式找到这个所谓的私有(private)方法在哪里,或者以某种方式绕过它。我在 twitter_feeds Controller 中的方法如下:

  def hometimeline
@user = User.find(current_user.id)

tweets = @user.tweeting.user_timeline(count: '10', include_entities: true)


parsed_tweets = []
i = 0

tweets.each do |tweet| 

  more = Hash.new
  more['test'] = tweet
  internal_hash = Hash.new
  mappings = {"source" => "fixed"}

  another = more['test']

  boo = Array(tweet)


  #newhash = Hash[twee.map {|k, v| [mapping[k], v] }]
  #newhash = Hash[more.map {|k, v| [mappings[k], v] }]
  #newhash = Hash[tweet.map {|k, v| [mappings[k] || k, v] }]

  internal_hash['parsed_text'] = tweet.entities

  internal_hash['id'] = tweet.id
  internal_hash['raw_text'] = tweet.text

  internal_hash['name'] = tweet.user.name
  internal_hash['screen_name'] = tweet.user.screen_name
  internal_hash['user_id'] = tweet.user.id
  internal_hash['user_image_url'] = tweet.user.profile_image_url
  parsed_tweets << internal_hash
  i = i + 1
end

respond_to do |format|
  format.json { render json: parsed_tweets }
end

结尾

本质上,我正在向客户端发送一组解析的推文,并希望在服务器上实现链接包装等。

有什么方法可以找到代码认为此方法在哪里,或者有没有办法使它不是私有(private)的或忽略它,以便我可以调用 tweet.entities。

编辑:需要注意的一点是,我确实有一个实体模型和实体 Controller ,但已经删除它们并且仍然得到它。

谢谢

最佳答案

原来这个错误是由 Twitter gem 引起的,他们有调用实体对象的方法,即 tweet.urls、tweet.user_mentions 等,而不是我想象的 tweet.entities.user_mentions。

文档在这里 http://rdoc.info/gems/twitter/Twitter/Tweet

关于ruby-on-rails-3.1 - 在 Twitter API 中使用 object.entities 的私有(private)方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11953718/

相关文章:

c++ - 运算符重载的私有(private)函数

JavaScript 私有(private)方法

ruby-on-rails - 如何防止 force_ssl 在重定向中破坏参数?

ruby-on-rails - 移除 Rails 3.1 中的事件记录错误

ruby-on-rails - 在 Rails 中,制作 Assets :precompile output the list of files it has precompiled?

c# - ASP.NET 中的 Twitter API 集成

json - nodejs - 解析分块的 twitter json

python - 将位置添加到 Twitter 情绪分析

c++ - C++中私有(private)成员函数的良好命名约定?

ruby-on-rails - Rspec 2-标签内的类名称