如何通过API从Twitter获取用户信息? [英] How get user info from twitter via API?

查看:3430
本文介绍了如何通过API从Twitter获取用户信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的API来整合轨应用与Twitter。

I'm developing API to integrate rails app with twitter.

我收到来自客户端只:



{
  provider:     'twitter',
  user_id:      'USER_ID',
  access_token: 'ACCESS_TOKEN'
}

但我需要创建用户,并将其保存到数据库中,如果用户不登记等我有模特用户验证(用户有很多认证):

But I need create user and save it into database if user is not registered etc. I have models user and authentication (user has many authentications):


class User
  validate :first_name, :last_name, :email, 
           presense: true 

  has_many :providers
endd

class Authentication
  validate :provider, :user_id, :access_token, :refresh_token, :expires_at, 
           presense: true

  belongs_to :user
end

已创建

Twitter的应用程序和所有权限的设置是否正确。

Twitter app is already created and all permissions are set up correctly.

问题:

要保存认证用户为DB - 我需要有各个领域

To save user with authentication into DB - I need to have all fields.

问:

如果我有提供商 USER_ID 的access_token
  我怎样才能得到更多的字段:
  电子邮件 FIRST_NAME 姓氏 refresh_token expires_at

If I have provider, user_id and access_token, how can I get additional fields: email, first_name, last_name, refresh_token and expires_at.

哪些API请求我应该?

Which API request should I make?

P.S。我发现,宝石推特我可以获取用户信息:

P.S. I found that with gem "twitter" I can get user information:


@client = Twitter::REST::Client.new do |config|
  config.consumer_key    = "TWITTER_API_KEY"
  config.consumer_secret = "TWITTER_API_SECRET"
end
user_info = @client.user 'USER_ID'

它返回用户信息的对象,其中包含 FIRST_NAME last_names
但我还是不知道如何获得电子邮件 refresh_token expires_at 字段。 (

推荐答案

嗯......我想你想创建一个日志为你的应用程序,是吗?

Hmm... I think you're trying to create a logging for your app, is it?

有没有这个API请求完全是,但你可以使用叽叽喳喳宝石这一点。希望它为你工作。

There is not API request for this exactly, but you can use the twitter gem for this. Hope it works for you.

https://github.com/sferik/twitter

这篇关于如何通过API从Twitter获取用户信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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