Help with fql.multiQuery - facebook

I'm playing around with the Facebook API's fql.multiQuery method. I'm just using the API Test Console, and trying to get a successful response but can't seem to figure out exactly what it wants.
Here's the text I'm entering into the "queries" field:
{"tags" : "select subject
from photo_tag
where subject != 601599551
and pid in (
select pid
from photo_tag
where subject = 601599551
)
and subject in (
select uid2
from friend
where uid1 = 601599551
)",
"foo" : "select uid from user where uid = 601599551"}
All it'll give me is a queries parameter: array expected. error.
I've also tried just about every permutation I could think of involving wrapping the name/query pairs in their own curly braces, adding brackets, adding whitespace, removing whitespace in case it didn't want an associative array (for those watching the edits, I just found out about these wonderful things now... oy), all to no avail. Is there something painfully obvious I'm missing here, or do I need to make like Chuck Norris Jon Skeet and simply will it to do my bidding?
Update: A note to anyone finding this question now: The fql.multiquery test console appears to be broken. You can test your query by clicking on the generated url in the test console and manually adding the "queries" parameter into the querystring.

Apparently I wasn't too far from the truth with the Jon Skeet comment... It seems the test console is VERY particular about what whitespace you can use where:
http://bugs.developers.facebook.com/show_bug.cgi?id=6403
This is what I ended up having to do with my code:
{"tags":"select subject from photo_tag where subject != 601599551 and pid in (select pid from photo_tag where subject = 601599551 ) and subject in (select uid2 from friend where uid1 = 601599551 )","foo":"select uid from user where uid = 601599551"}
Awesome. Because that's readable.

Related

Facebook API reading comments attachments

My trying to find a way to read all comments attachments.
This is what my status update looks like: http://screencast.com/t/sXqOzA3OsF
There's an attachment with the message "Mitt Bidrag".
I'm getting the correct json-stream using "me/feed" but it's missing information about the attachment.
This is what the feed looks like: http://screencast.com/t/sEL2iEsVOWu
I've tried a bunch of FQL-commands with the comment/attachment-table but I'm only retreiving.
Here are some examples of what I've tried:
- SELECT id, text, time, fromid FROM comment WHERE object_id='100002055769071_617700241641829' AND parent_id='0'
- SELECT id, text, time, fromid FROM comment WHERE object_id='617700241641829_653988868012966' AND parent_id='0'
- SELECT post_id, user_id FROM like WHERE post_id = "617700241641829_653988868012966"
- SELECT message FROM stream WHERE post_id = "617700241641829_653988868012966"
Response is: {
"data": [
]
}
Anyone have a solution?
Thanks a lot.
Try use this FQL query to get the comment details based on post ID:
SELECT id, text, post_id, comment_count, attachment.media.image.src
FROM comment
WHERE post_id = "617700241641829_653988868012966"
Please refer Comment-columns for more others comment details that you need to use.
Hope this can help to solve your problem.
This solved it:
SELECT attachment FROM comment WHERE id="617700241641829_653988868012966"

Facebook Graph API - Batch Request for large profile pictures

Trying to grab all of the users Facebook friends information which I can successfully do via a batch request:
NSString *jsonRequest1 = #"{ \"method\": \"GET\", \"relative_url\": \"me/friends?fields=name,picture\" }";
NSString *jsonRequestsArray = [NSString stringWithFormat:#"[%#]", jsonRequest1];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:jsonRequestsArray forKey:#"batch"];
[facebook requestWithGraphPath:#"me" andParams:params andHttpMethod:#"POST" andDelegate:self];
The profile pictures are small in size (50x50) and i need to specify the size of the photos. I've been looking at the graph API docs and i'm struggling to tie the two together - here's the related link: http://developers.facebook.com/docs/reference/api/user/
It says to add the following parameters to the request but like i said, i'm not sure how to tie the two together:
picture?type=large
I'm sure it would work for a single request for a particular user but i'm having no luck through a batch request.
Thanks for your help, it's probably staring me in the face!
The FQL has some advantage like Facebook stated
FQL, the Facebook Query Language, allows you to use a SQL-style
interface to query data exposed by the Graph API. It provides advanced
features not available in the Graph API, including batching multiple
queries into a single call.
Take a look at this tutorial from Facebook.
https://developers.facebook.com/docs/howtos/run-fql-queries-ios-sdk/
But I suggest to use Graph API with Field Expansion, this is very helpful and easier to understand than FQL. Note that Graph API doesn't support for all subfields.
https://developers.facebook.com/docs/reference/api/field_expansion/
Good luck man!
I don't think there is an easy way to do this using the Graph API. It is easy with this FQL query (which can be passed via a batch request):
SELECT uid, name, pic_big FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = me())
If you're looking for a specifically sized picture, take a look at the new profile_pic table.
This is possible by adding a height and width parameter to the URL. FB will attempt to provide you an image that matches your width and height criteria. Your batch would look something like this:
var batch= {
batch: []
};
batch.batch.push({
method: 'GET',
relative_url: fbid + '/picture?height=400&width=400'
});
FB.api('/', 'POST', batch, function (response) {
});
Something like that works for me:
{
"friends": "SELECT uid, name, pic_big FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())",
"profiles": "SELECT id, url, real_width, real_height FROM profile_pic WHERE id IN (SELECT uid FROM #friends) AND width = 300"
}
It's not perfect (two queries to scan) but it' one request.
Based on profile_pic table documentation.
Can be tested in FQL Explorer.

I am having problems running Facebook FQL queries that include long user ids

I am having problems running queries with FQL that include a supplied "Large"(beginning with 10000..) User ID
here is an example of one that is not working:
fql?q=SELECT uid, first_name,last_name,pic,pic_square,name
FROM user
WHERE uid=100002445083370
Is there a way to encapsulate the long number so it's passed as a string?
here is another example:
/fql?q=SELECT src_big
FROM photo
WHERE aid IN (SELECT aid
FROM album
WHERE owner=100002445083370 AND type="profile")
ORDER BY created DESC LIMIT 1
Has anyone been able to solve this issue? I am testing the queries in the graph explorer with no luck as well.
I see what the problem is,
The User id I am trying to pass is supposed to be: "100002445083367", but from querying the list of friends and grabbing their User Id, I am getting back "uid":1.0000244508337e+14 which is being shortened to: 100002445083370 (php removing the e+14) throwing off the second query. I need to make sure the id I am grabbing is staying as a string value not a number while I pass it back and forth from PHP and Javascript.
The problem is because of the way PHP handles JSON_DECODE. I had to modify Facebook PHP SDK and add a preg_replace previous to the json_decode. It will make sure json_decode doesn't convert large integers to floats by first converting them to strings.
here is the code:
line 803 from base_facebook.php:
$result = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $this->_oauthRequest($this->getUrl($domainKey, $path),$params)), true);
here is more information on the subject:
http://forum.developers.facebook.net/viewtopic.php?id=20846
What do you mean by "not working"?
That query works for me in Graph API explorer but the response is
{
"data": [
]
}
I think that user-id isn't valid; https://www.facebook.com/profile.php?id=100002445083370 gives a "Page not found" error for me.

Facebook - How to get the comments of a fb:comment

I need to get the comments posted on a fb:comments widget. Here is what I've tried:
http://graph.facebook.com/comments?id={{ url_of_the_page }} - Returns an empty list
Executing the following FQL
SELECT post_fbid, fromid, object_id, text, time
FROM comment
WHERE object_id IN
(SELECT comments_fbid
FROM link_stat
WHERE url ={{ page_url }}) - Return an empty response with the fql header
I'm beginning to think that this is not possible. Am I missing something or is this indeed not possible?
That is how you do it. What is the url you are trying? For example, this random Techcrunch article works in the same way as you describe:
http://graph.facebook.com/comments?id=http://techcrunch.com/2011/09/20/digg-experiments-with-topic-newsrooms-aggregates-news-by-most-meaningful-stories/

Facebook - migrating fb:comments from href to xid? [duplicate]

I've integrated fb:comments using the href parameter, but I am now stuck in a situation where I need to retrieve the comment count without fb:comment-count.
I normally use an FQL query such as below...
$result = $facebook->api(array(
'query' => 'SELECT post_id FROM comment WHERE xid = "' . $xid . '"',
'method' => 'fql.query'));
$comment_count = count($result);
However, there is no href column present in the comment table. Is there another way to do this? I have tried seeing if xid and href are interchangeable... no luck there. I'm also finding that fb:comments plugins created with xid id's are breaking a lot on me (see http://65beta.us/fb/fb1.php ).
Any advice would be greatly appreciated. Thanks!
You can easily reach comment and like counts like this: http://graph.facebook.com/?ids=http://65beta.us/fb/fb1.php