工具·食物热量查询
食物热量查询,食物卡路里大全

接口地址: https://58.linkpc.net/doc/food.html

返回格式: JSON

请求方式: GET

请求示例: https://58.linkpc.net/api/food?food=番茄

请求参数说明:

名称 必填 类型 说明
food string 食物
type string 返回格式默认JSON可选text

返回参数说明:

名称 类型 说明

返回示例:

{
"code": 201,
"msg": "失败",
"data": "抱歉,没有找到<%E7%95%AA%E8%8C%84>相关的食物!"
}

错误码格式说明:

名称 类型 说明

代码示例:

<?php
header('Content-type: application/json; charset=utf-8');
date_default_timezone_set('PRC');
$url = 'https://58.linkpc.net/api/food';
$type = isset($_GET['type']) ? $_GET['type'] : '';
if ($type == 'json' || $type == 'JSON') {
$result = file_get_contents($url . '?type=json');
echo htmlspecialchars($result);
} else {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);