2017-04-25 156 views
1

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

然而,为了获得访问令牌发布这个代码 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", 
       }, 
      }) 

     } 

显然其他人报告的问题,通过使用“应用程序/ x-WWW的形式,进行了urlencoded”发布的数据,JSON,这项目都得到了解决 - 但是现在这似乎不起作用。

这里是确切的错误信息返回:

{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" 

回答

2

grant_type应该是 'authorization_code'

1

数据对象转换成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", 
       }, 
      }) 

     }