简体   繁体   English

如何在Ruby中通过Instagram API获取用户名和/或ID?

[英]How can I get username and/or id through Instagram API in Ruby?

I'm not exactly sure how to call methods such as screen name in order to get the username and/or id with Instagram and Ruby: 我不确定如何调用方法(例如屏幕名称)以获取Instagram和Ruby的用户名和/或ID:

username = Instagram.configure do |config|
  config.client_id = "YOUR_CLIENT_ID"
  config.client_secret = "YOUR_CLIENT_SECRET"
  # For secured endpoints only
  #config.client_ips = '<Comma separated list of IPs>'
end

puts username.user

First, you need to give a link that will take you to Instagram, and you will be asked to enter your username and password, and get verified there. 首先,您需要提供一个链接,该链接会将您带到Instagram,然后将要求您输入用户名和密码,并在此处进行验证。

<%= link_to 'Click here to go to Instagram', '/oauth/connect' %>

In your routes file, 在您的路线文件中,

get '/oauth/connect' => 'users#connect'

In your UsersController class, 在您的UsersController类中,

def connect
  redirect Instagram.authorize_url(:redirect_uri => CALLBACK_URL)
end

CALLBACK_URL is crucial here; CALLBACK_URL在这里至关重要。 this is the link Instagram will redirect you once you enter your username and password on Instagram site. 这是链接,一旦您在Instagram网站上输入用户名和密码,Instagram就会重定向您。 When Instagram will hit on your CALLBACK_URL , you can do the following to get the parameters you have asked in your question: 当Instagram将点击您的CALLBACK_URL ,您可以执行以下操作以获取您在问题中询问的参数:

client = Instagram.client(:access_token => session[:access_token])
user = client.user
username = user.username

You can learn about other things at here . 您可以在这里了解其他信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM