0

美国农业部 API 参考链接:https ://ndb.nal.usda.gov/ndb/doc/apilist/API-SEARCH.md

我目前正在用 Python 创建一个引用 USDA 搜索 API 的程序。我尝试通过将 &ds=SR 添加到如下 API 链接中来将数据源参数设置为“标准参考”,但这不起作用。

https://api.nal.usda.gov/ndb/search/?format=json&q=butter&sort=n&max=25&offset=0&api_key=DEMO_KEY&ds=SR

我究竟做错了什么?我如何获得 API 链接以在结果中也显示不同食物的食物组?

谢谢!

4

1 回答 1

1

您收到此错误:

{
    "errors": {
        "error": [
            {
                "status": 400,
                "parameter": "ds",
                "message": "Unknown ds (Data Source) -- can be Branded Food Products or Standard Reference."
            }
        ]
    }
}

它暗示ds参数应该是Branded Food Productsor Standard Reference,所以再次尝试https://api.nal.usda.gov/ndb/search/?format=json&q=butter&sort=n&max=25&offset=0&api_key=DEMO_KEY&ds=Standard%20Reference ...瞧!

{
    "list": {
        "q": "butter",
        "sr": "1",
        "ds": "Standard Reference",
        "start": 0,
        "end": 25,
        "total": 104,
        "group": "",
        "sort": "n",
        "item": [
            {
                "offset": 0,
                "group": "Baked Products",
                "name": "Archway Home Style Cookies, Peanut Butter",
                "ndbno": "18541",
                "ds": "SR",
                "manu": "Archway Cookies"
            },
            {
                "offset": 1,
                "group": "Dairy and Egg Products",
                "name": "Butter, Clarified butter (ghee)",
                "ndbno": "01323",
                "ds": "SR",
                "manu": "none"
            },
            ...
于 2019-02-12T23:14:55.760 回答