2017-12-03 102 views
0

我正在嘗試使用Spotify API搜索功能來接收專輯數據。這是我的要求:Spotify API錯誤代碼400 - 沒有搜索查詢

request.post(authOptions, function(error, response, body) { 
if (!error && response.statusCode === 200) { 

// use the access token to access the Spotify Web API 
var token = body.access_token; 
var options = { 
    url: 'https://api.spotify.com/v1/search', 
    data: { 
     q: 'currents', 
     type: 'album', 
    }, 
    headers: { 
     'Authorization': 'Bearer ' + token 
    }, 
    json: true 
    }; 

request.get(options, function(error, response, body) { 
    console.log(body); 
    }); 
} 
}); 

然而,當這個代碼執行我不斷地得到一個錯誤代碼400 - 「無搜索查詢」響應。任何人都可以幫助找到爲什麼我的查詢選項沒有正確閱讀?

謝謝。

回答

2

解決方案:請求庫需要選項對象中名爲qs的查詢字符串對象。將「數據」更改爲「qs」將其固定。