从 Facebook Graph API 获取当前城市的国家/地区

发布于 2024-12-11 16:42:09 字数 223 浏览 0 评论 0原文

FB graph api 似乎总是为“当前城市”和“家乡”的美国字段返回“城市,州”,但似乎总是为“城市,国家”返回“城市,国家”美国以外的任何东西。

这是一个可靠的假设吗?除了美国还有其他国家会回归“城市、州”吗? FB 文档(https://developers.facebook.com/docs/reference/api/user/)没有解释这一点,我有点猜测我的方法。

FB graph api seems to always return "city, state" for USA fields of "current city" and "hometown", but seems to always return "city, country" for anything outside of the USA.

Is this a reliable assumption? Are there any other countries besides US that would return "city, state"? The FB Docs (https://developers.facebook.com/docs/reference/api/user/) don't explain this, and i'm kinda guessing my way around this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞陪衬 2024-12-18 16:42:09

我将使用 FQL 并查询 user current_location 字段的表,它将返回更全面且结构良好的响应:

SELECT current_location FROM user WHERE uid=me()

您可以尝试在 Facebook Graph API 资源管理器中使用新的 fql 端点。它将返回类似以下内容的内容:

{
  "data": [
    {
      "current_location": {
        "resultType": {
          "fieldTypes": {
            "street": {
              "strict": false
            },
            "city": {
              "strict": false
            },
            "state": {
              "strict": false
            },
            "country": {
              "strict": false
            },
            "zip": {
              "strict": false
            },
            "latitude": {
              "min": null,
              "max": null,
              "strict": false
            },
            "longitude": {
              "min": null,
              "max": null,
              "strict": false
            },
            "id": {
              "min": null,
              "max": null,
              "strict": false
            },
            "name": {
              "strict": false
            }
          },
          "includeNullFields": false
        },
        "street": null,
        "city": "Beirut",
        "state": "Beyrouth",
        "country": "Lebanon",
        "zip": "",
        "latitude": null,
        "longitude": null,
        "id": 106188806084417,
        "name": "Beirut, Lebanon"
      }
    }
  ]
}

请注意,citystatecountry 字段以及不一致 名称字段。

I would use the FQL and query the user table for the current_location field which would return a more comprehensive and well structured response:

SELECT current_location FROM user WHERE uid=me()

You can try is in the Facebook Graph API explorer using the new fql end-point. Which would return something like:

{
  "data": [
    {
      "current_location": {
        "resultType": {
          "fieldTypes": {
            "street": {
              "strict": false
            },
            "city": {
              "strict": false
            },
            "state": {
              "strict": false
            },
            "country": {
              "strict": false
            },
            "zip": {
              "strict": false
            },
            "latitude": {
              "min": null,
              "max": null,
              "strict": false
            },
            "longitude": {
              "min": null,
              "max": null,
              "strict": false
            },
            "id": {
              "min": null,
              "max": null,
              "strict": false
            },
            "name": {
              "strict": false
            }
          },
          "includeNullFields": false
        },
        "street": null,
        "city": "Beirut",
        "state": "Beyrouth",
        "country": "Lebanon",
        "zip": "",
        "latitude": null,
        "longitude": null,
        "id": 106188806084417,
        "name": "Beirut, Lebanon"
      }
    }
  ]
}

Notice the city,state and country fields are there along with the inconsistent name field.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文