如何在代码中使用PHP中Rapid API提供的数据?

时间:2018-11-13 13:15:25

标签: php api

$response = Unirest\Request::get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/search?number=10&offset=0&query=burger",
  array(
    "X-Mashape-Key" => "__PRIVATE_KEY__",
    "X-Mashape-Host" => "__REMOTE_HOST__"
  )
);

1 个答案:

答案 0 :(得分:1)

首先,我们需要从此链接https://github.com/Kong/unirest-php下载unirest-php php库

然后接下来创建php脚本并添加unirest

<?php 
require_once 'unirest-php/src/Unirest.php';   // here we add path of Unirest.php 

$response = Unirest\Request::get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/search?number=10&offset=0&query=burger",
  array(
    "X-Mashape-Key" => "privatekey",
    "X-Mashape-Host" => "spoonacular-recipe-food-nutrition-v1.p.mashape.com"
  )
);

echo "<pre>";

print_r($response);
 ?>

当我们运行这段代码时,我们会得到正确的响应输出

enter image description here

现在可以正常使用

快乐编程

谢谢, AS