我试图将数据存储在zomato api中并检查网站中生成的几个网址,例如,
<a href="https://developers.zomato.com/api/v2.1/restaurant?res_id=RESID">
https://developers.zomato.com/api/v2.1/restaurant?res_id=RESID,
我收到一条错误消息:
{&#34;代码&#34;:403,&#34;状态&#34;:&#34;禁止&#34;,&#34;消息&#34;:&#34;无效的API密钥&# 34;}
而这个相同的网址给出了一些关于某个餐馆的数据的json格式响应。另外,我生成了一个zomato API密钥。但是,问题。 请告诉我我错在哪里,以便我自己纠正。
谢谢。
答案 0 :(得分:0)
尝试从http请求的标头传递Zomato api密钥,而不是在查询字符串中传递密钥
答案 1 :(得分:0)
在javascript结构中,api以这种方式调用:
$.ajax({
url: "https://developers.zomato.com/api/v2.1/restaurant?res_id=RESID",
dataType: 'json',
async: true,
beforeSend: function(xhr){xhr.setRequestHeader('user-key',
'INSERT_API_KEY_HERE');}, // This inserts the api key into the HTTP header
success: function(response) { console.log(response) } });
答案 2 :(得分:0)
如果您试图获取API以获取响应数据。
通过标头传递API密钥
axios({
method: "GET",
url: "https://developers.zomato.com/api/v2.1/search",
headers: {
"user-key": "API_KEY",
"content-type": "application/json"
}
})
.then(response => {
console.log(response.data.restaurants[0].restaurant.name);
})
.catch(error => {
console.log(error);
});
答案 3 :(得分:-1)
const typedTextSpan = document.querySelector(".typed-text");
const cursorSpan = document.querySelector(".cursor");
const textArray = ["reconnaitre un talent ?", "détécter une opportunité ?"];
const typingDelay = 170;
const erasingDelay = 100;
const newTextDelay = 2000;
let textArrayIndex = 0;
let charIndex = 0;
function type() {
if (charIndex < textArray[textArrayIndex].length) {
if (cursorSpan.classList.contains("typing")) cursorSpan.classList.add("typing");
typedTextSpan.textContent += textArray[textArrayIndex].charAt(charIndex);
charIndex++;
setTimeout(type, typingDelay);
} else {
cursorSpan.classList.remove("typing");
setTimeout(erase, newTextDelay);
}
}
function erase() {
if (charIndex > 0) {
if (!cursorSpan.classList.contains("typing")) cursorSpan.classList.add("typing");
typedTextSpan.textContent = textArray[textArrayIndex].substring(0, charIndex - 1);
charIndex--;
setTimeout(erase, erasingDelay);
} else {
cursorSpan.classList.remove("typing");
textArrayIndex++;
if (textArrayIndex >= textArray.length) textArrayIndex = 0;
setTimeout(type, typingDelay + 1100);
}
}
document.addEventListener("DOMContentLoaded", function() {
if (textArray.length) setTimeout(type, newTextDelay + 250);
});