【问题标题】:Is it possible to authenticate on Instagram API by curl or in the application backend?是否可以通过 curl 或应用程序后端在 Instagram API 上进行身份验证?
【发布时间】:2016-06-16 10:33:37
【问题描述】:

在 Instagram 于 6 月 1 日更新他们的 API 后,我无法在没有登录 Instagram 帐户的情况下获得access token

是否可以跳过网站身份验证并通过 curl 或在我的应用程序后端进行?

【问题讨论】:

    标签: ruby-on-rails curl instagram instagram-api


    【解决方案1】:

    我最终为 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调用客户端

    【讨论】:

    • 您使用的网址是什么?我正在尝试使用 mechanize 也登录到我的 Instagram 帐户,但它没有在登录表单上显示。 agent.get('https://www.instagram.com/accounts/login/')agent.page.forms 为零。不知道这笔交易是什么。它无法识别该页面上的任何表单。
    • 其他人说你不能使用 mechanize 登录 instagram,因为没有反应支持。我最终使用 watir 登录并检索必要的数据。效果很好。
    【解决方案2】:

    聚会有点晚了,但万一有人发现你需要使用旧的登录 URL。 https://www.instagram.com/accounts/login/?force_classic_login

    这将允许您使用 Mechanize 登录,保存任何相关的 cookie。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 2022-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多