1

twitter gem を使用して、認証されたユーザーのすべてのフォロワーを取得したいと考えています。ただし、アプリケーションに登録された twitter id のフォロワーしか取得しません。

Twitterで登録されたアプリのコンシューマキー/シークレットを使用するイニシャライザにtwitter.rbがあります

Twitter.configure do |config|
    config.consumer_key = '****'
    config.consumer_secret = '****'
end

ログインするときは、Devise 経由で行います。次に、ユーザー プロファイルでユーザーを Twitter で認証し、その時点でトークンとシークレットを保存します。

def create
    auth = request.env["omniauth.auth"]
    currentAuthentication = Authentication.find_by_provider_and_uid(auth['provider'], auth['uid'])
    if currentAuthentication
        flash[:notice] = "Logged in successfully."
    else
        current_user.authentications.create(:provider => auth['provider'], :uid => auth['uid'], :token => auth['credentials']['token'], :secret => auth['credentials']['secret'])
        flash[:notice] = "Authentication successful."
    end

    redirect_to authentications_url
end

その後、保存した情報を使用してそのユーザーを認証し、フォロワーを取得したいと考えています。

  def getwords
    # authenticate at twitter
    authenticationDetails = current_user.authentications.first()
    wordClient = Twitter::Client.new(
        :oauth_token => authenticationDetails.token,
        :oauth_token_secret => authenticationDetails.secret
        )

    # get the users followers
    #wordClient.update("I'm tweeting using the Twitter Gem.")
    cursor = "-1"
    followerIds = []
    while cursor != 0 do
      followers = wordClient.follower_ids

      cursor = followers.next_cursor
      followerIds+= followers.ids
      sleep(2)
    end

    return followerIds
  end

wordClient.update を実行すると、登録されたアプリケーションからツイートが送信され、登録されたアプリケーションのフォロワーも取得されます。

ツイートを送信して、認証されたユーザーのフォロワーを取得することを期待していましたか? どこが間違っていますか?私が見つけることができたすべての例は、1 人のユーザーとの Twitter に基づいています。

4

0 に答える 0