I’m working with Facebook’s Graph API on iOS and running into an issue. When I search for users and get their profile data back, everything works fine for basic info like names and IDs. But when I try to get location information, it always comes back as null.
I’ve tested this with different approaches and even tried searching random names that return lots of results. Still can’t get location data from any of the users.
Here’s my current code:
NSString* searchQuery = [NSString stringWithFormat: @"search?q=%@&type=user", userName];
FBRequest *apiRequest = [FBRequest requestForGraphPath: searchQuery];
[apiRequest startWithCompletionHandler:
^(FBRequestConnection *connection, id response, NSError *error)
{
if (error)
{
// error handling
}
else
{
NSDictionary<FBGraphObject> *responseDict = (NSDictionary<FBGraphObject> *) response;
if (responseDict)
{
NSArray *results = [responseDict objectForKey:@"data"];
if (results)
{
for (FBGraphObject<FBGraphUser> *userObj in results)
{
// userObj contains valid id, name data
id<FBGraphPlace> userPlace = [userObj location];
// userPlace is always nil here
id<FBGraphLocation> geoLocation = [userPlace location];
NSString *cityName = [geoLocation city];
NSString *countryName = [geoLocation country];
NSString *placeName = userPlace.name;
}
}
}
}];
I also tried casting it differently but still get null results. Any ideas what might be wrong?
Yeah, this is expected now. Facebook locked down location data hard a few years ago because of privacy issues.
I hit the same wall on a project with location features. You can’t pull location data from user searches anymore, even with permissions.
The location field only works if users explicitly gave your app location access AND made their location public. For random searches like yours, it’ll always be null.
Adding location permissions to your app scope doesn’t help - it only works for users who specifically authorize your app. General user searches won’t give you location data.
If you need location info, you’ve got to:
Have users manually enter their location
Use device location services instead of Facebook data
Find a different approach that doesn’t rely on Facebook location
Your code’s fine. The API just doesn’t return that data anymore for privacy reasons.
fb broke location stuff after the cambridge analytica scandal. it’s all about privacy now, so your code won’t get location data unless it’s from a close friend who shared it with your app. been using their APIs for years and they keep takin features away without updates.
Facebook killed user search through the Graph API years ago because of privacy issues. They axed the /search endpoint for users around 2015-2017, so you’re basically hitting a dead endpoint - that’s why you’re getting null location data. Location info got locked down even before they removed search entirely. Most user location data needs permissions that regular apps just can’t get anymore. Facebook clamped down hard after all those privacy scandals. You’ll need to work around this - either ask users to enter their location manually or use device GPS with permission. Graph API user search is basically dead for third-party devs. Your best bet is using Facebook’s current login flow to grab basic profile info from users who actually consent to it.
Yeah, this is super frustrating with Facebook’s Graph API. They locked down the location field hard around 2014-2015 for privacy reasons. Even with the right permissions, you won’t get location data from most users because they’d have to explicitly make their location public - and basically nobody does that anymore. I hit this same wall building a social app a few years ago and wasted days thinking my code was broken. Truth is, Facebook killed most location sharing for user searches. You might get lucky with the friends endpoint if users granted location permissions, but success rates are terrible. I’d try different approaches - ask users to enter their location manually or use other location services if geography matters for your app.