Zomato api with angular

Deadly 提交于 2019-12-13 05:19:15

问题


I'm fairly new to coding and am having issues loading data from the Zomato API with angulars $http. I keep getting invalid API key popping up as an error in my console even though im using the API key generated by Zomato.

Here is a snippet of my code: http://jsfiddle.net/3j1c816v/1/

$http({
    method: 'GET',
    url: 'https://developers.zomato.com/api/v2.1/search?',
    params: {
        user_id: '', // API key
        entity_type: 'city', 
        q: 'food',
    }

Please let me know if i'm doing anything wrong or any helpful resources i can use to fix my issue!

Thank you


回答1:


user_key is not a GET parameter but a header parameter.

You should try this:

$http({
    method: 'GET',
    url: 'https://developers.zomato.com/api/v2.1/search?',
    headers: {'user_key' : 'api_key_goes_here'},
    params: {
        entity_type: 'city', 
        q: 'food',
    }
});


来源:https://stackoverflow.com/questions/33771792/zomato-api-with-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!