Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 我想在我的示例twitter rails应用程序中查找我所有追随者的推文_Ruby On Rails_Ruby_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 我想在我的示例twitter rails应用程序中查找我所有追随者的推文

Ruby on rails 我想在我的示例twitter rails应用程序中查找我所有追随者的推文,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我想找到跟踪用户的推文 用户模型 class User < ActiveRecord::Base has_many :tweets, dependent: :destroy has_many :relationships, foreign_key: "follower_id", dependent: :destroy has_many :followed_users, through: :relationships, source: :followed

我想找到
跟踪用户的推文

用户模型

class User < ActiveRecord::Base
    has_many :tweets, dependent: :destroy  
    has_many :relationships, foreign_key: "follower_id", dependent: :destroy  
    has_many :followed_users, through: :relationships, source: :followed
    has_many :reverse_relationships, foreign_key: "followed_id", class_name: "Relationship", dependent: :destroy
    has_many :followers, through: :reverse_relationships, source: :follower  
class Tweet < ActiveRecord::Base  
    belongs_to :user
class Relationship < ActiveRecord::Base  
    belongs_to :follower, class_name: "User"
    belongs_to :followed, class_name: "User
class用户
推特模式

class User < ActiveRecord::Base
    has_many :tweets, dependent: :destroy  
    has_many :relationships, foreign_key: "follower_id", dependent: :destroy  
    has_many :followed_users, through: :relationships, source: :followed
    has_many :reverse_relationships, foreign_key: "followed_id", class_name: "Relationship", dependent: :destroy
    has_many :followers, through: :reverse_relationships, source: :follower  
class Tweet < ActiveRecord::Base  
    belongs_to :user
class Relationship < ActiveRecord::Base  
    belongs_to :follower, class_name: "User"
    belongs_to :followed, class_name: "User
class Tweet
关系模型

class User < ActiveRecord::Base
    has_many :tweets, dependent: :destroy  
    has_many :relationships, foreign_key: "follower_id", dependent: :destroy  
    has_many :followed_users, through: :relationships, source: :followed
    has_many :reverse_relationships, foreign_key: "followed_id", class_name: "Relationship", dependent: :destroy
    has_many :followers, through: :reverse_relationships, source: :follower  
class Tweet < ActiveRecord::Base  
    belongs_to :user
class Relationship < ActiveRecord::Base  
    belongs_to :follower, class_name: "User"
    belongs_to :followed, class_name: "User
类关系
请帮我找到

class User < ActiveRecord::Base
    has_many :tweets, dependent: :destroy  
    has_many :relationships, foreign_key: "follower_id", dependent: :destroy  
    has_many :followed_users, through: :relationships, source: :followed
    has_many :reverse_relationships, foreign_key: "followed_id", class_name: "Relationship", dependent: :destroy
    has_many :followers, through: :reverse_relationships, source: :follower  
class Tweet < ActiveRecord::Base  
    belongs_to :user
class Relationship < ActiveRecord::Base  
    belongs_to :follower, class_name: "User"
    belongs_to :followed, class_name: "User
  • 所有my
    用户的推特都受到关注
  • 推文应由
    :created\u在
编辑:

我不想要Twitter的实际推文。我想要我的应用程序的推文。

首先,你需要了解如何将rails应用程序与Twitter集成。为了做到这一点,你必须使用Twitter API

  • 要将rails应用程序与Twitter集成,请阅读此博客 职位- .你可以跳过Facebook部分,只关注Twitter 整合

  • 一旦你有了Twitter身份验证,你就可以获得追随者的Twitter id或用户名

  • 现在,您可以阅读步骤2中追随者的所有推文


  • 这是一个有趣的尝试!我最近制作了一个基于浏览器的小游戏,使用twitter进行身份验证。在这样做的过程中,我发现以下资源非常有用:

    ,在github上,提供了一个如何将rails应用程序与twitter的API集成的项目示例。其中有很多很棒的代码,而且非常简单。我将该项目作为自己的基础

    Sferik还提供了gem和twitter CLI。这些将对您的旅程有所帮助

    除了中建议的资源之外,我还想参考。

    允许您在某种程度上这样做,但您不会从一次呼叫中获得追随者的tweet列表

    以下是我的做法:


    集成

    与Twitter连接不再是oAuth的情况,您必须通过

    您需要使用启用Rails应用程序:

    #config/initializers/twitter.rb
    #creates a constant
    TWITTER = Twitter::REST::Client.new do |config|
      config.consumer_key        = "YOUR_CONSUMER_KEY"
      config.consumer_secret     = "YOUR_CONSUMER_SECRET"
      config.access_token        = "YOUR_ACCESS_TOKEN"
      config.access_token_secret = "YOUR_ACCESS_SECRET"
    end
    
    然后您可以直接调用Twitter API:

    #app/views/shared/footer.html.erb
    <%= TWITTER.followers(213747670) %>
    

    您可以像这样从控制台运行rake任务:
    rake tweets:latest

    我想知道如何做,而不是使用API