pxgamer / spoonacularapi
Spoonacular 营养、食谱和食品 API 允许您访问超过 360,000 个食谱和 80,000 个食品产品。
Requires
- php: >=5.6
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- apimatic/jsonmapper: ~1.3
- mashape/unirest-php: ~3.0
Requires (Dev)
- phpunit/phpunit: ^5.7 || ^6.4 || ^7.0
- squizlabs/php_codesniffer: ^3.1
README
Spoonacular 营养、食谱和食品 API 允许您访问超过 360,000 个食谱和 80,000 个食品产品。
安装
通过 Composer
$ composer require pxgamer/spoonacularapi
用法
初始化 API 客户端需要以下信息。
参数 | 描述 |
---|---|
xMashapeKey | 您想在此会话中使用的 Mashape 应用程序。 |
API 客户端可以按以下方式初始化。
// Configuration parameters $xMashapeKey = "xMashapeKey"; // The Mashape application you want to use for this session. $client = new SpoonacularAPIClient($xMashapeKey);
获取单例实例
可以从 API 客户端访问 APIController
类的单例实例。
$client = $client->getClient();
getProductInformation
标签:
跳过身份验证
获取包装食品产品的信息。
function getProductInformation($id)
参数
参数 | 标签 | 描述 |
---|---|---|
id | 必需 默认值 |
包装食品产品的 ID。 |
示例用法
$id = 22347; $result = $client->getProductInformation($id);
findSimilarRecipes
标签:
跳过身份验证
找到与给定食谱相似的食谱。
function findSimilarRecipes($id)
参数
参数 | 标签 | 描述 |
---|---|---|
id | 必需 默认值 |
要找到相似食谱的源食谱的 ID。 |
示例用法
$id = 156992; $result = $client->findSimilarRecipes($id);
getAutocompleteIngredientSearch
标签:
跳过身份验证
自动完成对成分的搜索。
function getAutocompleteIngredientSearch($query)
参数
参数 | 标签 | 描述 |
---|---|---|
查询 | 必需 默认值 |
查询 - 部分或完整的成分名称。 |
示例用法
$query = 'appl'; $result = $client->getAutocompleteIngredientSearch($query);
createVisualizePriceBreakdown
标签:
跳过身份验证
可视化食谱的价格分解。
function createVisualizePriceBreakdown( $ingredientList, $servings, $defaultCss = 'checked', $mode = 1, $fieldParameters = NULL)
参数
参数 | 标签 | 描述 |
---|---|---|
ingredientList | 必需 默认值 |
食谱的成分列表,每行一个成分。 |
份量 | 必需 默认值 |
份数。 |
defaultCss | 可选 默认值 |
是否应该使用默认 CSS 样式化小部件。 |
mode | 可选 默认值 |
小部件应该交付的模式。1 = 分离视图(紧凑),2 = 所有视图(完整)。 |
fieldParameters | 可选 |
此方法支持额外的可选表单参数。 |
示例用法
$ingredientList = '3 oz flour'; $servings = 2; $defaultCss = 'checked'; $mode = 1; // key-value map for optional form parameters $formParams = array('key' => 'value'); $result = $client->createVisualizePriceBreakdown($ingredientList, $servings, $defaultCss, $mode, $formParams);
createVisualizeNutrition
标签:
跳过身份验证
将食谱的营养信息可视化。
function createVisualizeNutrition( $ingredientList, $servings, $defaultCss = 'checked', $fieldParameters = NULL)
参数
参数 | 标签 | 描述 |
---|---|---|
ingredientList | 必需 默认值 |
食谱的成分列表,每行一个成分。 |
份量 | 必需 默认值 |
份数。 |
defaultCss | 可选 默认值 |
是否使用默认CSS样式来设置成分列表。 |
fieldParameters | 可选 |
此方法支持额外的可选表单参数。 |
示例用法
$ingredientList = '3 oz flour'; $servings = 2; $defaultCss = 'checked'; // key-value map for optional form parameters $formParams = array('key' => 'value'); $result = $client->createVisualizeNutrition($ingredientList, $servings, $defaultCss, $formParams);
createVisualizeIngredients
标签:
跳过身份验证
可视化食谱的成分。
function createVisualizeIngredients( $ingredientList, $servings, $defaultCss = 'checked', $measure = 'metric', $view = 'grid', $fieldParameters = NULL)
参数
参数 | 标签 | 描述 |
---|---|---|
ingredientList | 必需 默认值 |
食谱的成分列表,每行一个成分。 |
份量 | 必需 默认值 |
初始份数。 |
defaultCss | 可选 默认值 |
是否使用默认CSS样式来设置成分列表。 |
计量单位 | 可选 默认值 |
初始计量单位,可以是“metric”或“us”。 |
视图 | 可选 默认值 |
初始视图,可以是“grid”或“list”。 |
fieldParameters | 可选 |
此方法支持额外的可选表单参数。 |
示例用法
$ingredientList = '3 oz flour'; $servings = 2; $defaultCss = 'checked'; $measure = 'metric'; $view = 'grid'; // key-value map for optional form parameters $formParams = array('key' => 'value'); $result = $client->createVisualizeIngredients($ingredientList, $servings, $defaultCss, $measure, $view, $formParams);
getSummarizeRecipe
标签:
跳过身份验证
用简短文本总结食谱。
function getSummarizeRecipe($id)
参数
参数 | 标签 | 描述 |
---|---|---|
id | 必需 默认值 |
要总结的食谱的ID。 |
示例用法
$id = 4632; $result = $client->getSummarizeRecipe($id);
searchGroceryProducts
标签:
跳过身份验证
搜索包装食品产品,如冷冻披萨和士力架巧克力棒。
function searchGroceryProducts( $query, $number = 10, $offset = 0, $queryParameters = NULL)
参数
参数 | 标签 | 描述 |
---|---|---|
查询 | 必需 默认值 |
搜索查询。 |
数量 | 可选 默认值 |
要检索的结果数量,默认为10。 |
偏移量 | 可选 默认值 |
要跳过的结果数量,默认为0。 |
查询参数 | 可选 |
此方法支持额外的可选查询参数。 |
示例用法
$query = 'snickers'; $number = 10; $offset = 0; // key-value map for optional query parameters $queryParams = array('key' => 'value'); $result = $client->searchGroceryProducts($query, $number, $offset, $queryParams);
getQuickAnswer
标签:
跳过身份验证
回答一个与营养相关的自然语言问题。
function getQuickAnswer($q)
参数
参数 | 标签 | 描述 |
---|---|---|
q | 必需 默认值 |
与营养相关的问题。 |
示例用法
$q = 'How much vitamin c is in 2 apples?'; $result = $client->getQuickAnswer($q);
getRecipeInformation
标签:
跳过身份验证
获取有关食谱的信息。
function getRecipeInformation($id)
参数
参数 | 标签 | 描述 |
---|---|---|
id | 必需 默认值 |
食谱的ID。 |
示例用法
$id = 156992; $result = $client->getRecipeInformation($id);
createParseIngredients
标签:
跳过身份验证
从纯文本中提取成分。
function createParseIngredients( $ingredientList, $servings)
参数
参数 | 标签 | 描述 |
---|---|---|
ingredientList | 必需 默认值 |
食谱的成分列表,每行一个成分。 |
份量 | 必需 默认值 |
你可以用这些成分制作多少份。 |
示例用法
$ingredientList = '3 oz pork shoulder'; $servings = 2; $result = $client->createParseIngredients($ingredientList, $servings);
createMapIngredients
标签:
跳过身份验证
将成分映射到食品产品。
function createMapIngredients( $ingredientList, $servings)
参数
参数 | 标签 | 描述 |
---|---|---|
ingredientList | 必需 默认值 |
新行分隔的成分列表。 |
份量 | 必需 默认值 |
此食谱可以制作多少份。 |
示例用法
$ingredientList = '200g flour\\n3 eggs'; $servings = 1; $result = $client->createMapIngredients($ingredientList, $servings);
getExtractRecipeFromWebsite
标签:
跳过身份验证
从食谱博客或网页中提取食谱数据。
function getExtractRecipeFromWebsite( $url, $forceExtraction = false, $queryParameters = NULL)
参数
参数 | 标签 | 描述 |
---|---|---|
url | 必需 默认值 |
食谱页面的URL。 |
forceExtraction | 可选 默认值 |
如果为真,无论我们是否已经知道食谱,都会触发提取。仅在信息缺失时使用,因为这个操作较慢。 |
查询参数 | 可选 |
此方法支持额外的可选查询参数。 |
示例用法
$url = 'http://www.melskitchencafe.com/the-best-fudgy-brownies/'; $forceExtraction = false; // key-value map for optional query parameters $queryParams = array('key' => 'value'); $result = $client->getExtractRecipeFromWebsite($url, $forceExtraction, $queryParams);
getComputeDailyMealPlan
标签:
跳过身份验证
计算一天的餐单。
function getComputeDailyMealPlan( $targetCalories, $timeFrame)
参数
参数 | 标签 | 描述 |
---|---|---|
targetCalories | 必需 默认值 |
每天的目标卡路里数。 |
timeFrame | 必需 默认值 |
对于一天或整个星期,允许的值是 "day" 和 "week"。 |
示例用法
$targetCalories = 2000; $timeFrame = 'day'; $result = $client->getComputeDailyMealPlan($targetCalories, $timeFrame);
createClassifyGroceryProductsBatch
标签:
跳过身份验证
给定一组产品json,获取分类后的产品。
function createClassifyGroceryProductsBatch($productJsonArray)
参数
参数 | 标签 | 描述 |
---|---|---|
productJsonArray | 必需 集合 |
产品的JSON数组。 |
示例用法
$productjsonarray = new Productjsonarray(); $productJsonArray = array($productjsonarray); $result = $client->createClassifyGroceryProductsBatch($productJsonArray);
createClassifyCuisine
标签:
跳过身份验证
对食谱的菜系进行分类。
function createClassifyCuisine( $ingredientList, $title)
参数
参数 | 标签 | 描述 |
---|---|---|
ingredientList | 必需 默认值 |
食谱的成分列表,每行一个成分。 |
title | 必需 默认值 |
食谱的标题。 |
示例用法
$ingredientList = '3 oz pork shoulder'; $title = 'Pork roast with green beans'; $result = $client->createClassifyCuisine($ingredientList, $title);
createClassifyAGroceryProduct
标签:
跳过身份验证
给定一个杂货产品标题,此端点允许您检测它是哪种基本成分。
function createClassifyAGroceryProduct($productJson)
参数
参数 | 标签 | 描述 |
---|---|---|
productJson | 必需 |
产品的JSON表示。 |
示例用法
$productJson = new Productjson(); $result = $client->createClassifyAGroceryProduct($productJson);
searchRecipes
标签:
跳过身份验证
使用自然语言搜索食谱。
function searchRecipes( $query, $cuisine = 'italian', $diet = 'vegetarian', $excludeIngredients = 'coconut', $intolerances = 'egg, gluten', $limitLicense = false, $number = 10, $offset = 0, $type = 'main course', $queryParameters = NULL)
参数
参数 | 标签 | 描述 |
---|---|---|
查询 | 必需 默认值 |
(自然语言)食谱搜索查询。 |
cuisine | 可选 默认值 |
食谱的菜系。以下菜系中的一个或多个(以逗号分隔):african, chinese, japanese, korean, vietnamese, thai, indian, british, irish, french, italian, mexican, spanish, middle eastern, jewish, american, cajun, southern, greek, german, nordic, eastern european, caribbean, 或 latin american。 |
diet | 可选 默认值 |
食谱必须遵守的饮食。可能的值是:pescetarian, lacto vegetarian, ovo vegetarian, vegan, 和 vegetarian。 |
excludeIngredients | 可选 默认值 |
必须不包含在食谱中的成分或成分类型的逗号分隔列表。 |
intolerances | 可选 默认值 |
不耐受物的逗号分隔列表。所有找到的食谱都不能含有可能导致具有给定不耐受性的人出现问题的成分。可能的值是:dairy, egg, gluten, peanut, sesame, seafood, shellfish, soy, sulfite, tree nut, 和 wheat。 |
limitLicense | 可选 默认值 |
是否应该有开放许可,允许以适当的归属显示。 |
数量 | 可选 默认值 |
要返回的结果数(介于0到100之间)。 |
偏移量 | 可选 默认值 |
要跳过的结果数(介于0到900之间)。 |
type | 可选 默认值 |
菜谱的类型。以下之一:主菜、配菜、甜点、开胃菜、沙拉、面包、早餐、汤、饮料、酱汁或饮品。 |
查询参数 | 可选 |
此方法支持额外的可选查询参数。 |
示例用法
$query = 'burger'; $cuisine = 'italian'; $diet = 'vegetarian'; $excludeIngredients = 'coconut'; $intolerances = 'egg, gluten'; $limitLicense = false; $number = 10; $offset = 0; $type = 'main course'; // key-value map for optional query parameters $queryParams = array('key' => 'value'); $result = $client->searchRecipes($query, $cuisine, $diet, $excludeIngredients, $intolerances, $limitLicense, $number, $offset, $type, $queryParams);
findByNutrients
标签:
跳过身份验证
查找一组符合给定营养限制的菜谱。所有找到的菜谱都将包含在卡路里、蛋白质、脂肪和碳水化合物限制内的宏量营养素。
function findByNutrients( $maxcalories = 1500, $maxcarbs = 100, $maxfat = 100, $maxprotein = 100, $mincalories = 0, $minCarbs = 0, $minfat = 0, $minProtein = 0, $queryParameters = NULL)
参数
参数 | 标签 | 描述 |
---|---|---|
maxcalories | 可选 默认值 |
菜谱可包含的最大卡路里数。 |
maxcarbs | 可选 默认值 |
菜谱可包含的最大碳水化合物克数。 |
maxfat | 可选 默认值 |
菜谱可包含的最大脂肪克数。 |
maxprotein | 可选 默认值 |
菜谱可包含的最大蛋白质克数。 |
mincalories | 可选 默认值 |
菜谱必须包含的最小卡路里数。 |
minCarbs | 可选 默认值 |
菜谱必须包含的最小碳水化合物克数。 |
minfat | 可选 默认值 |
菜谱必须包含的最小脂肪克数。 |
minProtein | 可选 默认值 |
菜谱必须包含的最小蛋白质克数。 |
查询参数 | 可选 |
此方法支持额外的可选查询参数。 |
示例用法
$maxcalories = 1500; $maxcarbs = 100; $maxfat = 100; $maxprotein = 100; $mincalories = 0; $minCarbs = 0; $minfat = 0; $minProtein = 0; // key-value map for optional query parameters $queryParams = array('key' => 'value'); $result = $client->findByNutrients($maxcalories, $maxcarbs, $maxfat, $maxprotein, $mincalories, $minCarbs, $minfat, $minProtein, $queryParams);
findByIngredients
标签:
跳过身份验证
查找尽可能使用给定成分且缺失成分尽可能少的菜谱。这是您的冰箱API端点。
function findByIngredients( $ingredients, $limitLicense = false, $number = 5, $ranking = 1, $queryParameters = NULL)
参数
参数 | 标签 | 描述 |
---|---|---|
ingredients | 必需 默认值 |
应包含的成分列表,以逗号分隔。 |
limitLicense | 可选 默认值 |
是否只显示带有归属许可的菜谱。 |
数量 | 可选 默认值 |
返回的最大菜谱数(默认=5)。 |
ranking | 可选 默认值 |
是首先最大化使用的成分(1)还是最小化缺失的成分(2)。 |
查询参数 | 可选 |
此方法支持额外的可选查询参数。 |
示例用法
$ingredients = 'apples,flour,sugar'; $limitLicense = false; $number = 5; $ranking = 1; // key-value map for optional query parameters $queryParams = array('key' => 'value'); $result = $client->findByIngredients($ingredients, $limitLicense, $number, $ranking, $queryParams);
createRecipeCard
标签:
跳过身份验证
根据菜谱创建菜谱卡片。
function createRecipeCard( $backgroundImage, $image, $ingredients, $instructions, $mask, $readyInMinutes, $servings, $title, $author = 'Emily Henderson', $backgroundColor = '#ffffff', $fontColor = '#333333', $source = 'spoonacular.com', $fieldParameters = NULL)
参数
参数 | 标签 | 描述 |
---|---|---|
backgroundImage | 必需 默认值 |
背景图片("none"、"background1" 或 "background2")。 |
image | 必需 默认值 |
菜谱的二进制图片,格式为jpg。 |
ingredients | 必需 默认值 |
食谱的成分列表,每行一个成分。 |
instructions | 必需 默认值 |
制作菜谱的说明。每行一个步骤。 |
mask | 必需 默认值 |
覆盖菜谱图片的掩码("ellipseMask"、"diamondMask"、"diamondMask"、"starMask"、"heartMask"、"potMask"、"fishMask")。 |
readyInMinutes | 必需 默认值 |
将菜谱摆上餐桌所需的时间(分钟)。 |
份量 | 必需 默认值 |
你可以用这些成分制作多少份。 |
title | 必需 默认值 |
食谱的标题。 |
author | 可选 默认值 |
菜谱的作者。 |
backgroundColor | 可选 默认值 |
菜谱卡片上的背景颜色,格式为十六进制字符串。 |
fontColor | 可选 默认值 |
菜谱卡片上的字体颜色,格式为十六进制字符串。 |
source | 可选 默认值 |
菜谱的来源。 |
fieldParameters | 可选 |
此方法支持额外的可选表单参数。 |
示例用法
$backgroundImage = 'background1'; $image = The image.; $ingredients = '2 cups of green beans'; $instructions = 'cook the beans'; $mask = 'ellipseMask'; $readyInMinutes = 60; $servings = 2; $title = 'Pork tenderloin with green beans'; $author = 'Emily Henderson'; $backgroundColor = '#ffffff'; $fontColor = '#333333'; $source = 'spoonacular.com'; // key-value map for optional form parameters $formParams = array('key' => 'value'); $result = $client->createRecipeCard($backgroundImage, $image, $ingredients, $instructions, $mask, $readyInMinutes, $servings, $title, $author, $backgroundColor, $fontColor, $source, $formParams);
变更日志
请参阅变更日志获取有关最近更改的更多信息。
测试
$ composer test
贡献
请参阅CONTRIBUTING和CODE_OF_CONDUCT获取详细信息。
安全
如果您发现任何与安全相关的问题,请发送电子邮件至owzie123@gmail.com,而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件获取更多信息。