rICh
rICh

Reputation: 1709

Getting Current City's Country from Facebook Graph API

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.

Upvotes: 1

Views: 5146

Answers (1)

ifaour
ifaour

Reputation: 38135

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.

Upvotes: 4

Related Questions