fql.query for page_admin table does not return any results - facebook-fql

I am new to Facebook development. I was using following query to return the page_id of the pages that I created as page admin. This query returns nothing when I execute it in Test Console.
http://developers.facebook.com/docs/reference/rest/fql.query/
Please let me know
1. whether Facebook still uses the below tables to store the information
2. Whether the query is correct.
See below the query.
select page_id,name,has_added_app from page where page_id in (select page_id from page_admin where uid=me())
Is this is due to any permissions? What do I have to do to return page_id info of the pages I created? Thanks a lot for any help.

Use this url https://developers.facebook.com/tools/explorer/?fql=SELECT page_id FROM page_admin WHERE uid = your user id here

Related

Facebook FQL Get All Posts At Location

The location_post FQL table is described as the following:
An FQL table that returns Posts that have locations associated with
them and that satisfy at least one of the following conditions:
you were tagged in the Post
a friend was tagged in the Post
you authored the Post
a friend authored the Post
So I wrote the following FQL script with the intent of getting all posts my friends and I had made at a certain location:
SELECT id, message, post_id, timestamp FROM location_post WHERE page_id=303736809701751
However, an empty data set is returned. In this particular case, I expect some of my own posts to be returned, though I have tried other place ids that should have returned friends' posts as well.
What is missing from the request, or is this a bug I should report to Facebook?
The paragraph you quoted from the doc just says that the table only contains places where yourself and friends of yours have been. It tries to explain that you will not find public users there.
A query to the location_post table does not automatically specify the concerned IDs for you. If you want to search for the places where all your friends have been, you will have to indicate all your friends. If you are only interested by a bunch of friends, just add the concerned IDs.
This should do it.
SELECT id, message, post_id, timestamp
FROM location_post
WHERE (author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
OR author_uid = me()
OR tagged_uids IN (SELECT uid2 FROM friend WHERE uid1 = me())
OR tagged_uids = me())
AND page_id = 303736809701751

Get latitude/longitude of friend's current_location using Graph FQL

I'm trying to get the latitude/longitude of all of a user's friends using a single API call. I believe I need to write a multi-query FQL statement, but I can't get the syntax correct.
I believe the two queries need to be something like the following:
'"friends":"SELECT uid,current_location FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"'
'"location":"SELECT location FROM page WHERE id IN (SELECT current_location_id FROM #friends)"';
My problem is that somehow I need to get the ID of the current_location in the first query so that I can reference it in the second query, but I only know how to get an array that contains the id.
Thanks for any help!
Clarification:
I'm not trying to get check-ins of friends. Instead I want to graph the "current_location" (i.e. where they live) of all of a user's friends on a Geo map. I can get a user's "current_location" with the following FQL query:
"SELECT uid,sex,current_location FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"
This query returns the following array:
[current_location] => Array
(
[city] => New York
[state] => New York
[country] => United States
[zip] =>
[id] => 108424279189115
[name] => New York, New York
)
Which does not contain the longitude and latitude of the of the current_location (New York in the above example)
Therefore I now need to take the ID of the current_location (e.g. 108424279189115) and run a second FQL query such as:
"SELECT location,name FROM page WHERE page_id = 108424279189115)"
To get the latitude and longitude of the current_location. Currently, I have a working code that runs the first FQL query, then extracts page_id in php, and then runs a second FQL query to get the current_location latitude/longitude. However, for performance reasons I would like to run only one multi-query if this is possible.
Edit:
The query should work by adjusting the second query to:
'"location":"SELECT location FROM page WHERE id IN (SELECT current_location.id FROM #friends)"';
When working with an array type in the FB API you can access the value in any query by doing array.value
Also, if all you need is the page's id, you'll probably get better performance by doing current_location.id in your first query
You're going to want to use a fql.multiquery, there is a similair answer here that can be tailored to your needs: Facebook Graph API get all users and their status
The FQL documentation on multiquery is located here: http://developers.facebook.com/docs/reference/fql/
Also are you trying to get the lat/long of a checkin object? If so you need to take a look at this resource: http://developers.facebook.com/docs/reference/fql/checkin/
Edit:
I'm not sure that what you are trying to do is possible. I just looked through the api and tested some queries, the only way you could get the lat/long from a friend seems to be based on a checkin, from there you can get details on the page if necessary... Even looking at your second query, current_location_id is not referenced anywhere in the page table, and selecting location from the page table is going to give you location info on the place that it pertains to. Maybe you could elaborate more on what you're trying to accomplish.
Here is a multiquery statement I wrote in PHP using FQL (it will select the coordinates of all your friends check ins, then from there get details on the place of the checkin pertaining to that friend):
try{
$multiQuery = "{
'query1':'SELECT coords, tagged_uids, page_id FROM checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me())',
'query2':'SELECT name, description FROM page WHERE page_id IN (SELECT page_id FROM #query1)'
}";
$param = array(
'method' => 'fql.multiquery',
'queries' => $multiQuery,
'callback' => ''
);
$queryresults = $facebook->api($param);
print_r($queryresults);
}
catch(Exception $o){
print_r($o);
}
fql?q=SELECT location,name FROM page WHERE page_id in (SELECT current_location.id from user where uid in(select uid2 from friend where uid1=me()))
this will do the magic for you
facebook.batch_fql({
'query1': "SELECT uid, name, current_location.id FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())",
'query2': "SELECT page_id, name, description, location FROM page WHERE page_id IN (SELECT current_location.id FROM #query1)"
})
will return two responses
one will be a list of friends UIDs, names and their current locations IDs
the other will be a list of unique location IDs with their name, description and geolocation info
EDIT: if you query for current_location using FQL, you'll get the full latlong in the first response and you don't even need the second one

FQL console throw "Ops" error

I have this FQL query
select uid, name, website
from user
where website != "" and uid in (
select uid2
from friend
where uid1 = me()
)
I tested this query in the FQL console a couple of months ago, and it worked fine. Now I try it again and I have this error:
that can be translated in english like "An error occurred. We are working to solve it soon". I tried with different queries and no one work, all throw the same error. Someone have any suggestions?
Since an unspecified version, Facebook doesn't allow to query some private parameters (like the websites). So my old query is not valid now.

Search for people by name in FQL

I'm trying to develop a search for people by name feature using the Facebook API.
I'm trying this FQL query:
SELECT uid, username, name, pic_square FROM user WHERE strpos(name, 'Alfredo Artiles') >= 0
But I get an "Your statement is not indexable. The WHERE clause must contain an indexable column." error.
I also tried to add a "and uid > 0" condition, but that didn't work too.
Any idea?
SELECT uid, username, name, pic_square FROM user WHERE contains('Alfredo Artiles')
I have no idea why it works, as it violates the "at least and indexable field in WHERE", but it does.
EDIT: this is where I read it: link
later edit
Ok, sorry for the mistake regarding strpos, I didn't remeber it existence last time i checked the fql docs. The thing about it is that it can be used just in certain cases. You need to have a primar indexable column in your where clause and a second condition with strpos (at least this is how I succeded using it). For example:
SELECT actor_id, message FROM stream WHERE source_id = me() AND strpos(message, 'stuff') > 0 limit 50
I hope this clarifies a little bit the confusion with this function.
U need to specify the uid in where clause fetch details in facebook user table. we don't get the the all user details.here get the details of currently logged in user
"SELECT name FROM user WHERE uid IN(SELECT uid2 FROM
friend WHERE uid1 = me()) AND strpos(name,'Alfredo Artiles') >=0"
YES, YOU CAN!!!
Try to search in profile table, instead of user table. In profile table, the name field is indexable, so your statement would have to change only a bit:
SELECT id, username, name, pic_square FROM profile WHERE contains('alfredo artiles') and type='user'
Contains is not case-sensitive while strpos is. You could still use lower and strpos, but you would also have the problem of special characters. Contains is the solution.
You can find all fields of profile table in facebook doc:
Hope it helps!

Facebook current UID with FQL

How can i get my current UID with FQL.. i want to save traffic and requests with getting the the friends of a user with fql.multiquery
"query1": GET NEED MY USERID
"query2":"SELECT uid, first_name, last_name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=MYUSERID) order by first_name"
should return my friends! getting users with friends.get and then users.getInfo needs 2 requests and is not optimal...
Thank you
Your first query should be entirely unnecessary, as Facebook always provides the uid to an application via the fb_sig_user parameter (POST or GET). I'm not sure what kind of FQL query you could use to get a uid based on some other form of information. There's no sessions table or anything available to FQL (available tables are listed here).
For multi-queries however, I'm fairly certain that this page describes exactly what you need to do, but I'll throw some code together in the way that I would do it.
If it was a PHP app, and I wanted to do this server side, I would create a couple of JSON-formatted strings and send them as a query as follows:
$fql= '{
"userinfo":"SELECT uid FROM user_standard_info WHERE first_name=\'zombat\'",
"friends":"SELECT uid2 FROM friend WHERE uid1 IN (SELECT uid FROM #userinfo)}"
}';
$res = $facebook->api_client->fql_multiquery($fql);
print_r($res['userinfo']);
print_r($res['friends']);
This should produce a dump of your query results.
Assuming you have your current uid available from the fb_sig_user parameter (which you should), then your problem should be solved by something like this:
$fql= '{
"friends":"SELECT uid2 FROM friend WHERE uid1='.$your_uid.',"
"friendinfo":"SELECT * FROM standard_user_info WHERE uid IN (SELECT uid2 FROM #friends)"
}';
$res = $facebook->api_client->fql_multiquery($fql);
Note: You may want to have a careful look at some of the queries you're trying to do. Many tables, such as friend, can only be used if you're dealing with a logged-in user.
The function me() returns your user id in FQL.
To get the list of your friends, you can use:
SELECT uid, first_name, last_name
FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
You can find the documentation of this here: http://developers.facebook.com/docs/reference/fql/