How do I search Facebook for all users at a certain location using Graph-API - facebook

I have a project where I have to search Facebook for all people at a
certain location and then apply further filters to the data. My problem and question is:
How do I get the initial data, using Graph API?
I know that it is possible, using the search field in Facebook itself. Just typing "All people living in ???" returns a list of people.
I couldn't find such functionality in the Graph-API of Facebook. Here is what I tried:
I modified some parameters of the standard search request
search?type=user&center=52.946758,-1.172882&distance=1000
search?type=user&center=Nottingham&distance=1000
and here is what I got:
{
"error": {
"message": "No node specified",
"type": "GraphMethodException",
"code": 100
}
}
Using a similar query with location instead of center
search?type=user&location=Nottingham&distance=1000
search?type=user&location=52.946758,-1.172882&distance=1000
search?type=user&q=&location=Nottingham
and only got a confusing error that the location I wrote is wrong
{
"error": {
"message": "(#160) Invalid coordinates. Coordinates must contain at least latitude and longitude.",
"type": "OAuthException",
"code": 160
}
}
Then searching for a user with the coordinates as query parameter returned an empty result.
search?type=user&q=52.946758,-1.172882&distance=1000
{"data": []}
Then I tried to search for a correct location to pass to the location parameter of the query
search?type=location&q=52.946758,-1.172882
and I only got a deprecation error
{
"error": {
"message": "(#12) location search is deprecated for versions v2.0 and higher",
"type": "OAuthException",
"code": 12
}
}
I don't know how to get to this. If someone could tell me, how to get this information, it would help
me a lot, since I don't know what to try next.
I have found this question similar to my problem, but the accepted answer isn't really answering the question
Facebook Search API - List all users based on location?

You can either search for a location OR search for a user, but you can definitely not search for "all users in an area". The Graph search on Facebook can handle a lot more things that you will never be able to get with the API. Think about privacy, i would not want any app to know if i am nearby, without even authorizing the App ;)
Facebook docs: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search
For getting the locatoin where the user is living, you need to check out the user reference: https://developers.facebook.com/docs/graph-api/reference/v2.2/user
There is a "location" field in there, you need to authorize a user with the "user_location" permission to get that information. It is not possible to get that information from any user. Just because you can see data on Facebook and it is public does not mean you can access it with an App, for privacy reasons this is only possible by authorizing the user.
Scraping without an App is not allowed btw, check out the scraping terms: https://www.facebook.com/apps/site_scraping_tos_terms.php

I tried this -> "firstname lastname location" and it works perfect.
For example -> "Sameeksha kumari australia"
The query looks like this
https://graph.facebook.com/v2.5/search?fields=id,name,picture.type(normal),location&limit=500&q=sameeksha kumari melbourne&type=user&access_token=token

Related

Graph API tells me an object doesn't exist while it does

I'm starting to create a little app to get the names associated with Facebook IDs for a bigger project. I just started to use the Facebook API and it's giving me weird results. Most of the time, everything works fine. I use this code (I'm using Python, but that doesn't really matter here since it's the Facebook API that is causing the problem) :
def downloadString(url, params):
cookie = {}
data = requests.get(url,cookies=cookie,params=params)
return data.text
url = "https://graph.facebook.com/v2.6/"
id = "afriendidhere"
dl = basics.downloadString(url + id, {"access_token":accesstoken})
res = json.loads(dl)
As I said, most of the time, it works just fine, giving me the name of the given person. Though, for two people in my friends list, I get the following message :
{
"error": {
"message": "Unsupported get request. Object with ID 'theid' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"fbtrace_id": "FTfrh78XjW/"
}
}
I don't understand why. The person with this id does exist, since I can access the page http://facebook.com/messages/theid and it's giving me my conversation history with this user. It's always the same people who cause the error, everyone else works perfecty.
Does anyone know why ?
You are only supposed to get data from users who authorized your App. Authorized them, get their App Scoped ID and name with the /me endpoint. More information: https://developers.facebook.com/docs/graph-api/reference/v2.6/user
The solution for me was to publish the page in settings
Page Visibility --> Publish
Save changes
Try removing any visibility limitations from your Page's settings (such as country restrictions etc)

Facebook Graph API Explorer returns OAUTH Exception

In the Graph API Explorer tool I'm using this query:
search?q=myemail#gmail.com&type=user
But for whatever reasons I'm getting this returned.
{
"error": {
"message": "(#200) Must have a valid access_token to access this endpoint",
"type": "OAuthException",
"code": 200
}
}
The access token is there. And other requests work, like this one:
me?fields=id,name
Here's the return value
{
"id": "somelongnumber",
"name": "my name"
}
Not sure what I'm doing wrong, are there additional permissions that I have to setup to get search to work?
Edit: Here's the screenshot of my user permissions:
I have also tried using an application token, but same thing.
More updates:
Querying for names seem to work just fine:
search?q=FirstName LastName&type=user
returns valid results, but email returns me oath exception. Did facebook change the way they allow for email searches?
Even though it was possible, you can't search users by their e-mail addresses anymore. As the doc states, the q value must refer to the name of a user.
Available Search Types
Type: user
Description: search for a person (if they allow their name to be searched for)
q value: name
Also the dot character which is/are present in every e-mail address would also break your Graph request. In the current Graph API syntax, . marks the beginning of a subfield, for instance:
/me?fields=friends.limit(10)
^
How would the email be delimited? As you can see,
/search?q=john#gmail&type=user "works"
whereas
/search?q=john#gmail.com&type=user doesn't.
Edit: This feature has been disabled in April 2013 and Facebook reported:
This functionality was deprecated because
of low utilization, and we have no current plans to re-enable it. If
you have a valid use case for this feature please describe it here for
consideration. Marie Hagman — Facebook Team
Source: https://developers.facebook.com/x/bugs/453298034751100/

Facebook Graph API OAuthException Code: 9 Access denied. Why?

I am using facebook Graph API to get user data with the below query
https://graph.facebook.com/search?q=xxx yyy zzzz&type=user&access_token=myTokenHere
And the reply is;
{
"error": {
"message": "(#9) Access denied",
"type": "OAuthException",
"code": 9
}
}
And also it makes my account to logoff from developer.facebook.com. When I try refreshing that web site it says I am logged out.
I am used to use this account for making this search, this happened suddenly. I made maybe a thousand successful search with this link, with this user with this query.
It doesn't says I am limited or something.
I googled it a lot and made a lot of research but couldn't find any solution to it.

Unusual behavior of facebook grap API ("type": "GraphMethodException", "code": 100)

I am having some unusual errors while fetching some data for some users via graph API.
As for example w all know we can get basic user info via graph.facebook.com/username
And it works. But it is not working for some users. Like the user www.facebook.com/sanzida.tanzum is a valid facebook user. So, we should get her basic info via graph.facebook.com/sanzida.tanzum. But when you will try that, you will get the error
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
And it is not a permission issue because use user herself gets the same error when she try to retrive her own data via graph API. Actually the user sanzida.tanzum is invisible to graph API. For example user sanzida.tanzum is on my friend list. You can check here. my friendlist.(it is public). But when I retrive my friendlist via graph API, my friendlist is shown excluding the user sanzida.tanzum ! But she is in my friendlist!
I have tried to contact facebook for this matter because I did not find any doccument related to this matter. They replied it is usual. (probably they did not read my mail at all. I am including the email conversation with facebook)
Hi তৌফিক,
They are getting errors because they are not you... they dont have
permissions to see the same things you do. They might also be missing
an access token. Either way: no bug here.
Thanks,
Emrakul Security Facebook
-----Original Message----- From: *****#ovi.com To: Subject: Report a Security Vulnerability - Unusual bug in facebook graph API
Your Email Address: *****#ovi.com Do you have technical details of
a security vulnerability?: Yes Vulnerability Type: Privacy /
Authentication Vulnerability Scope: Platform Developer API Title:
Unusual bug in facebook graph API Product / URL:
https://graph.facebook.com/sanzida.tanzum Description and Impact: I
was doing some graph API calls for testing purpose. Mostly I was doing
mostly user profile calls. (https://graph.facebook.com/exampleuser)
Somehow I realized facebook is giving following errors for some users
even they are on my friendlist. Same thing occurs when they try by
themselves.
As for eample the user "https://www.facebook.com/sanzida.tanzum" is on
my friendlist. (My friendlist is public.You can check if you want.)
So, according to facebook graph API, I can request the user's basic
info using (https://graph.facebook.com/sanzida.tanzum) But it returns
this error:
"{ "error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100 } }"
Actually graph API can't access nothing of this user. Another
example.. When I request my friendlist via graph API , All friends of
my friendlist is shown except the user (sanzida.tanzum). But she is in
my friendlist! check here (my friendlist is public)
"https://www.facebook.com/toufiqueimam/friends". So why is this
happening only for few users?
Just now I got confirmation that the user herself gets the same error
if she tries to access (https://graph.facebook.com/sanzida.tanzum)
{ "error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100 } }
Reproduction Instructions / Proof of Concept: Reproduction: first go
to https://www.facebook.com/sanzida.tanzum You will see it is a valid
profile. Now try https://graph.facebook.com/sanzida.tanzum You will
get following error
{ "error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100 } }
This isn't a bug, the error means that the data you're trying to access is not accessible to you, does not exist, has been deleted, is not available because you haven't provided an access token from a user who can see it, etc.
See this answer for an example of this error message in relation to Facebook pages: https://stackoverflow.com/a/6847088/21062 - the same is true when trying to access user profiles if that user has blocked you, blocked your app, disabled their account or disabled all apps from accessing their information.
Just an FYI, I ran into this problem, and it wasn't because the user had blocked all applications. In my scenario, my application was attempting to force-convert Facebook's 64 bit integers into a 53 bit JavaScript integer (Node application). It was mangling the value, so when I was making the Facebook GET Request later on in my application lifecycle, I was doing so with the mangled value, and Facebook was trying to tell me "Um, this UserId doesn't exist".
So in my application, I had to use the Node Big-integer add-on, along with the Mongoose mongoose-long plugin for my Mongodb.
Long story short, if you are converting the UserId to it's native 64 bit integer, don't do so unless the intger type in your application is at least 64 bits.

Open Graph user own created object issue

I'm following the documentation here:
https://developers.facebook.com/docs/opengraph/using-object-api/
Using the following:
/me/objects/<app-namespace>:<created-object>?privacy={"value":"SELF"}
&object={"image":"https://<image-url>"}&access_token=<user-token>
Testing with the Graph API tool i'm getting this error:
{
"error": {
"message": "(#200) Requires extended permission: publish_actions",
"type": "OAuthException",
"code": 200
}
}
Ok well that seems obvious until I debug the access token:
Valid True
Origin Mobile Web Faceweb
Scopes publish_actions, user_friends
Anyone else seen this or have an idea of how to fix it?
EDIT Ok so I had publish_actions in both User & Friends and Extended permissions. I removed the User & Friends permission and now I get this:
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1
}
}
Me no like unknown.
Ok so a couple things to note here that went wrong.
I picked an object type as an item thinking it would be <myapp>:item in the call. Well as it turns out the item is actually a product type so it is product.item a global type. What is handy is to actually click the get code link on the objects you create. Solution was to actually create my own app object type, which I thought I had.
In the Graph API make sure you actually use the application pull down in the top right to select the right app. I noticed some issues when it was set to the generic Graph API Explorer app.
Silly mistakes but cost me some time, hope it helps someone else.