I'm currently building an app using Deezer API hosted on Heroku. When I run the application locally (i'm located in Canada), i get search results. When the app is deployed on Heroku, i get no results
body: '{"data":[],"total":0}' }
The search function is :
exports.searchByTrack = function (req, res) {
search('http://api.deezer.com/search/track?', req.query.q, res);
};
function search(url, searchQuery, res) {
url += qs.stringify({
q: searchQuery
});
request({
uri: url,
method: 'GET'
},
function (error, response, body) {
console.log(JSON.stringify(response), JSON.stringify(body));
if (!error && response.statusCode === 200) {
searchSuccess(res, JSON.parse(body));
} else {
searchError(res, error, response, body);
}
}
);
}
I've found that some other people have no results because of the region of their server: Why Deezer search API is not returning results on deployed cloud application and Deezer API: Search result is empty
It says to add a token to requests to get support. I've updated my search function to add a token to request :
function search(url, searchQuery, res) {
url += qs.stringify({
q: searchQuery,
access_token: 'nyeLL0j9d953e221bcbee5flp77Zqu553e221bcbee98mkAWOsT'
});
....
}
I still get : body: '{"data":[],"total":0}' }
Is there a way to make it work on Heroku ? Or is there a workaround to pretend i'm in another country?
Do you know where the servers of Heroku are located? It seems to be the same problem than the example you gave. SO if you want to make it work, you have to pass an access_token parameter with the request. If the access_token is associated with a Premium user who registered in a Deezer live country (e.g. Italy for example), the request will take the user country associated with the token into account. Therefore, it will return results. That above workaround isn't working for free users.