Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7590579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:26:10+00:00 2026-05-30T20:26:10+00:00

The Facebook Graph API provides a user’s current location in two formats: name and

  • 0

The Facebook Graph API provides a user’s current location in two formats: name and ID. ID can be something like 104022926303756. Name can be something like Palo Alto, California or Beijing, China. From these two fields, how do I extract the country? All American locations are in the form [City], [State] whereas all non-American locations are in the form [City], [Country]. Can I code something less hacky than:

$states = array(
 'Alabama'
 'Alaska',
 'Arizona',
 // ...
);

$country = 'USA';
if (!in_array($locationName, $states)) {
    preg_match('#, ([a-z]+$)#i', $locationName, $match);
    $country = $match[1];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:26:11+00:00Added an answer on May 30, 2026 at 8:26 pm

    How about using this: http://developers.facebook.com/tools/explorer/?method=GET&path=fql%3Fq%3DSELECT%20current_location%20FROM%20user%20WHERE%20uid%3Dme()

    ?

    As you can see, using FQL on user table, the JSON you’ll receive is something like:

    {
      "data": [
        {
          "current_location": {
            "city": "Turin", 
            "state": "Piemonte", 
            "country": "Italy", 
            "zip": "", 
            "id": 115351801811432, 
            "name": "Turin, Italy"
          }
        }
      ]
    }
    

    There you have the field country, much more readable 🙂

    EDIT: The link is broken because brakets are missing at the end of query, anyway the FQL query is:

    SELECT current_location FROM user WHERE uid=me()
    

    “me()” can be any user ID.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to Facebook graph API we can request a user profile picture with this
I know how to use graph api - https://graph.facebook.com/{id}/feed|posts to get user's and page's
Does facebook graph api provide support for searching Post messages by specific location?
I want to access the Facebook Graph API and get JSON responses like this:
Can I use the Facebook Graph API without the creation of my Facebook Application?
I'm using the Facebook Graph API and want to check if a user has
Using Facebook Graph API (PHP), How to find how long a user is using
Facebook Connect seems like the cool new way to leverage a user's Facebook account
Facebook API: How to let the php knows whether the user is a fan
Does Facebook provide a URL the user can access that will take him to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.