【问题标题】:Instagram authentication API not returning access tokenInstagram 身份验证 API 未返回访问令牌
【发布时间】:2017-04-25 15:05:05
【问题描述】:

用于验证用户身份并为他们提供会话访问令牌的 instagram“服务器端工作流程”不起作用。第一部分的工作原理是我可以从这里获取代码: https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code

但是,当将此代码发布到 https://api.instagram.com/oauth/access_token 为了获得访问令牌,它只响应“您必须提供客户 ID”,即使我已将其作为表单数据的一部分提供 - 与我最初用于获取代码的客户 ID 相同!

这是我正在使用的代码:

getIgToken: function (igCode) {
            let data = {
                client_id: config.imported.instagram.client_id,
                client_secret: config.imported.instagram.client_secret,
                grant_type: 'authorization_code',
                redirect_uri: 'http://localhost:5000/app/scrape',
                code: igCode
            }
            return $http({
                method: 'POST',
                url: 'https://api.instagram.com/oauth/access_token',
                data: data,
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
            })

        }

显然其他人报告了将数据发布为 json 的问题,然后通过使用“application/x-www-form-urlencoded”解决了这些问题 - 但是现在这似乎也不起作用。

这是返回的确切错误消息:

{error_type: "OAuthException", code: 400, error_message: "You must provide a 
client_id"}
code:400
error_message:"You must provide a client_id"
error_type:"OAuthException"

【问题讨论】:

    标签: javascript angularjs authentication oauth instagram


    【解决方案1】:

    grant_type 应该是 'authorization_code'

    【讨论】:

      【解决方案2】:

      将数据对象转成json格式,试试

       data: JSON.stringify(data),
      

      您的代码将如下所示

      getIgToken: function (igCode) {
                  let data = {
                      client_id: config.imported.instagram.client_id,
                      client_secret: config.imported.instagram.client_secret,
                      grant_type: 'authorisation_code',
                      redirect_uri: 'http://localhost:5000/app/scrape',
                      code: igCode
                  }
      var jsonData= JSON.stringify(data)
                  return $http({
                      method: 'POST',
                      url: 'https://api.instagram.com/oauth/access_token',
                      data: jsonData,
                      headers: {
                          "Content-Type": "application/x-www-form-urlencoded",
                      },
                  })
      
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-24
        • 2014-05-30
        • 1970-01-01
        • 1970-01-01
        • 2022-07-27
        • 2018-04-23
        • 1970-01-01
        • 2017-04-29
        相关资源
        最近更新 更多