【发布时间】:2016-06-16 10:33:37
【问题描述】:
在 Instagram 于 6 月 1 日更新他们的 API 后,我无法在没有登录 Instagram 帐户的情况下获得access token。
是否可以跳过网站身份验证并通过 curl 或在我的应用程序后端进行?
【问题讨论】:
标签: ruby-on-rails curl instagram instagram-api
在 Instagram 于 6 月 1 日更新他们的 API 后,我无法在没有登录 Instagram 帐户的情况下获得access token。
是否可以跳过网站身份验证并通过 curl 或在我的应用程序后端进行?
【问题讨论】:
标签: ruby-on-rails curl instagram instagram-api
我最终为 Ruby 使用了 mechanize gem
我在InstagramPage类中做了self方法:
def self.instagram_client
return @instagram_client if @instagram_client.present? &&
@instagram_client.access_token.present?
# Logging in to Instagram
url = Instagram.authorize_url(redirect_uri: ENV['INSTAGRAM_REDIRECT_URL'],
response_type: 'token')
agent = Mechanize.new
agent.get(url)
agent.page.forms[0]['username'] = ENV['INSTAGRAM_USERNAME']
agent.page.forms[0]['password'] = ENV['INSTAGRAM_PASSWORD']
agent.page.forms[0].submit
# Retrieving access_token from url and setting it to Instagram client
access_token = agent.page.uri.to_s.split('=')[-1]
@instagram_client = Instagram.client(access_token: access_token)
end
现在我可以通过运行InstagramPage.instagram_client调用客户端
【讨论】:
agent.get('https://www.instagram.com/accounts/login/') 但 agent.page.forms 为零。不知道这笔交易是什么。它无法识别该页面上的任何表单。
聚会有点晚了,但万一有人发现你需要使用旧的登录 URL。 https://www.instagram.com/accounts/login/?force_classic_login
这将允许您使用 Mechanize 登录,保存任何相关的 cookie。
【讨论】: