Zomato API具有角 [英] Zomato api with angular

查看:209
本文介绍了Zomato API具有角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是相当新的编码和我有从angulars $ HTTP的Zomato API加载数据的问题。我不断收到无效的API密钥雨后春笋般冒出来作为我的控制台错误,即使利用Zomato生成的API密钥IM。

下面是我的code的一个片段: http://jsfiddle.net/3j1c816v/1/

  $ HTTP({
    方法:GET,
    网址:https://developers.zomato.com/api/v2.1/search?,
    params:一个{
        USER_ID:'',// API密钥
        ENTITY_TYPE:城市,
        问:食物,
    }

请让我知道,如果我做错了什么或任何有用的资源,我可以用它来解决我的问题!

感谢您


解决方案

user_key 不是一个GET参数,但一个标题参数。

您应该试试这个:

\r
\r

$ HTTP({\r
    方法:GET,\r
    网址:https://developers.zomato.com/api/v2.1/search?,\r
    标题:{'user_key':'api_key_goes_here},\r
    params:一个{\r
        ENTITY_TYPE:城市,\r
        问:食物,\r
    }\r
});

\r

\r
\r

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

解决方案

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',
    }
});

这篇关于Zomato API具有角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆