2017-12-03 94 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”将其固定。