2017-04-25 151 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", 
       }, 
      }) 

     }