【问题标题】:Using the USDA API使用美国农业部 API
【发布时间】:2019-02-12 23:11:36
【问题描述】:

USDA 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 链接以在结果中也显示不同食物的食物组?

谢谢!

【问题讨论】:

    标签: python api usda-fooddata-central-api


    【解决方案1】:

    您收到此错误:

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

    它提示ds 参数应该是Branded Food ProductsStandard 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"
                },
                ...
    

    【讨论】:

      猜你喜欢
      • 2012-01-29
      • 1970-01-01
      • 2023-01-21
      • 2022-06-29
      • 2014-03-30
      • 2011-02-23
      • 2011-02-25
      • 1970-01-01
      • 2021-05-30
      相关资源
      最近更新 更多