Unexpected behavior when using FQL - facebook

Adding the LIMIT option to an FQL causes MORE results to return than without the LIMIT.
For an example:
SELECT post_id, actor_id, message,description,type FROM stream WHERE source_id = me()
returns 4 results:
{ "data": [
{
"post_id": "1458319848_4164228991531",
"actor_id": 1458319848,
"message": "Oh happy days!",
"description": null,
"type": 46
},
{
"post_id": "1458319848_4081409841104",
"actor_id": 1458319848,
"message": "",
"description": "Caroline Natan and Or Karlinsky are now friends.",
"type": null
},
{
"post_id": "1458319848_4076275592751",
"actor_id": 1458319848,
"message": "",
"description": "Caroline Natan changed her Interested In.",
"type": null
},
{
"post_id": "1458319848_4075703458448",
"actor_id": 100001179537125,
"message": "",
"description": null,
"type": 237
}]}
But using:
SELECT post_id, actor_id, message,description,type FROM stream WHERE source_id = me() LIMIT 9
returns 5 results:
{"data": [
{
"post_id": "1458319848_4164228991531",
"actor_id": 1458319848,
"message": "Oh happy days!",
"description": null,
"type": 46
},
{
"post_id": "1458319848_4081409841104",
"actor_id": 1458319848,
"message": "",
"description": "Caroline Natan and Or Karlinsky are now friends.",
"type": null
},
{
"post_id": "1458319848_4076275592751",
"actor_id": 1458319848,
"message": "",
"description": "Caroline Natan changed her Interested In.",
"type": null
},
{
"post_id": "1458319848_4075703458448",
"actor_id": 100001179537125,
"message": "",
"description": null,
"type": 237
},
{
"post_id": "1458319848_4069875152744",
"actor_id": 100000876758120,
"message": "",
"description": null,
"type": 237
}]}
Of course this DOESN'T MAKE ANY SENSE!
Am I missing something here? if so, what? Also I've read this, I didn't see anything regarding the problem described here.
Thanks in advance.

The article you linked to actually addresses this issue:
You might notice that the number of results returned is not always equal to the “limit” specified. This is expected behavior. Query parameters are applied on our end before checking to see if the results returned are visible to the viewer. Because of this, it is possible that you might get fewer results than expected.
Which basically means that facebook filters the results after it executes the query.
In your example, in the first query, there's an implicit limit, say 5. Out of these 5 results, 1 is filtered out because of visibility restrictions and you get 4.
In the second query, the server gets 10 results, filters 5 of them out based on visibility and returns 5 to you.

Related

Get list of related tracks HTTP API SoundCloud

I wasn't able to find anything fitting in HTTP API documentation.
As I know, there's some tracks popping out in SC widget after current track is finished, therefore there is some related tracks functionality in SC itself, yet can we access it via API?
I.e get a list of tracks, related to given track's id.
Disclaimer: This is an undocumented endpoint and is subject to change at anytime by SoundCloud.
There is an undocumented endpoint that allows you to access a track's related sounds:
HTTP GET: https://api.soundcloud.com/tracks/[TRACK_ID]/related?client_id=[YOUR_CLIENT_ID]
You didn't specify a language, so i'm just going to give a high-level overview on how to use the endpoint.
First, get your track URL. I'll use this one as an example: https://soundcloud.com/msmrsounds/ms-mr-hurricane-chvrches-remix
Then hit the resolve endpoint to get the track_id.
HTTP GET: https://api.soundcloud.com/resolve.json?url=https%3A%2F%2Fsoundcloud.com%2Fmsmrsounds%2Fms-mr-hurricane-chvrches-remix&client_id=[YOUR_CLIENT_ID]
Response:
{
"status": "302 - Found",
"location": "https://api.soundcloud.com/tracks/90787841.json?client_id=[YOUR_CLIENT_ID]"
}
Next, hit the related endpoint with your track_id.
HTTP GET: https://api.soundcloud.com/tracks/90787841/related?client_id=[YOUR_ClIENT_ID]
The full response will give you up to 50 related tracks. The response is too large to post, but it's just an array of tracks.
[
{
"kind": "track",
"id": 112741336,
"created_at": "2013/09/27 09:40:29 +0000",
"user_id": 59817646,
"duration": 215896,
"commentable": true,
"state": "finished",
"original_content_size": 38068298,
"last_modified": "2015/04/04 20:17:24 +0000",
"sharing": "public",
"tag_list": "CHVRCHES Whitney Houston Zane Lowe",
"permalink": "chvrches-its-not-right-but-its",
"streamable": true,
"embeddable_by": "all",
"downloadable": false,
"purchase_url": null,
"label_id": null,
"purchase_title": null,
"genre": "Electronic",
"title": "CHVRCHES - It's Not Right But It's Okay (Whitney Houston Cover)",
"description": "CHVRCHES - It's Not Right But It's OK (Whitney Houston Cover) from Zane's Live Sessions",
"label_name": "",
"release": "",
"track_type": "recording",
"key_signature": "",
"isrc": "",
"video_url": null,
"bpm": null,
"release_year": null,
"release_month": null,
"release_day": null,
"original_format": "wav",
"license": "all-rights-reserved",
"uri": "https://api.soundcloud.com/tracks/112741336",
"user": {
"id": 59817646,
"kind": "user",
"permalink": "uknewmusic",
"username": "UKNewMusic",
"last_modified": "2013/09/27 09:38:04 +0000",
"uri": "https://api.soundcloud.com/users/59817646",
"permalink_url": "http://soundcloud.com/uknewmusic",
"avatar_url": "https://a1.sndcdn.com/images/default_avatar_large.png"
},
"permalink_url": "http://soundcloud.com/uknewmusic/chvrches-its-not-right-but-its",
"artwork_url": "https://i1.sndcdn.com/artworks-000058757165-6tnuep-large.jpg",
"waveform_url": "https://w1.sndcdn.com/XkEffI5hwjZ7_m.png",
"stream_url": "https://api.soundcloud.com/tracks/112741336/stream",
"playback_count": 680326,
"download_count": 0,
"favoritings_count": 9241,
"comment_count": 199,
"attachments_uri": "https://api.soundcloud.com/tracks/112741336/attachments",
"policy": "ALLOW"
},
{ ...
}
]

Querying application stats with aggregate by

I am migrating code to v2.2 of the API and need to separate the clicks/impressions between unique and non unique.
The API docs ask us to pass count and uu as values for the aggregateBy modifier which if i pass uu it returns an error->
/v2.2/appid12345/app_insights/story_impressions?aggregateBy=uu
{
"error": {
"message": "(#100) Param aggregateBy must be one of {COUNT, USERS, TOPK, SUM, USD_SUM, UNKNOWN_USERS}",
"type": "OAuthException",
"code": 100
}
}
But if i pass USERS as the error message states i get json returned
/v2.2/appid12345/app_insights/story_impressions?aggregateBy=USERS
{
"data": [
{
"time": "2015-01-15T08:00:00+0000",
"value": "56"
},
{
"time": "2015-01-16T08:00:00+0000",
"value": "128"
},
{
"time": "2015-01-17T08:00:00+0000",
"value": "196"
},
{
"time": "2015-01-18T08:00:00+0000",
"value": "420"
},
{
"time": "2015-01-19T08:00:00+0000",
"value": "304"
},
{
"time": "2015-01-20T08:00:00+0000",
"value": "176"
},
{
"time": "2015-01-21T08:00:00+0000",
"value": "128"
}
]
}
My questions is- can i assume the USERS value with the modifier returns the unique count? and the COUNT values returns the non unique?
Its been reported to facebook as a bug
https://developers.facebook.com/bugs/412068288957160/

Facebook FQL: Get group post status photos

I am trying to pull the photos from a user's post within a group. Posts in a group seem to be either created as a 'photo' or 'status'.
I am able to pull the photos from a post within the group when it is created as a 'photo' using this:
SELECT attachment FROM stream WHERE post_id="<postid>"
But if the post was created as a 'status' this query doesn't return any data for the attachment.
Here is an example of a post created as a 'status' and what the results are. No data for attachment (photo) when I know there is a photo that goes with that post.
SELECT attachment, type, message, created_time FROM stream WHERE post_id = '<postid>'
{
"data": [
{
"attachment": {
"description": ""
},
"type": 308,
"message": "Ceramic wall hanging with mirror from Spain (6\"x8\") $5 pickup in SR",
"created_time": 1379101402
}
]
}
Is this a permissions thing or am I just not pulling from the correct table(s) for this type of post?
Thanks
Chris
Just saying that it works fine for me:
SELECT post_id, attachment, type, message, created_time FROM stream WHERE post_id="POST_ID"
POST_ID looking like: 481234567779150_559912345679366. The permissions I use are user_groups and user_friends.
{
"data": [
{
"post_id": "481234567779150_559912345679366",
"attachment": {
"media": [
{
"href": "https://www.facebook.com/photo.php?fbid=10123450&set=gm.5599123456789366&type=1&relevant_count=1",
"alt": "bla bla bla",
"type": "photo",
"src": "https://fbcdn-photos-f-a.akamaihd.net/hphotos-ak-prn1/1013188_102013456789034740_1177097408_s.jpg",
"photo": {
"aid": "65904234567838363",
"pid": "65904345678990795",
"fbid": "10202345678934740",
"owner": 1533245678910,
"index": 1,
"width": 1032,
"height": 581,
"images": [
{
"src": "https://fbcdn-photos-f-a.akamaihd.net/hphotos-ak-prn1/1013188_10123456789_1177097408_s.jpg",
"width": 130,
"height": 73
}
]
}
}
],
"name": "",
"caption": "",
"description": "",
"properties": [
],
"icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif",
"fb_object_type": "photo",
"fb_object_id": "65123456789090795"
},
"type": 308,
"message": "bla bla bla",
"created_time": 1373368884
}
]
}
Did you try your query in the Graph API Explorer? Can you give more information? What kind of group is it, secret, public? Is the user one of your friend? I personally tried with both public or private groups and friend or non-friend posts. Can you confirm this happens with other 308-type posts with a photo and on several groups?

How do I determine the object that was liked by a user?

I'm doing a FQL query to get posts from a user:
{
"feeds": "SELECT type, actor_id, target_id, app_data, action_links, permalink, post_id, viewer_id, created_time, updated_time, source_id, message, description, attachment FROM stream WHERE filter_key = 'owner' AND source_id = <userId> AND is_hidden = 0 LIMIT 50"
}
For the most part, the results are great. However, if the result contains a post about the user "liking" something, how can I determine what was "liked"?
For example:
{
"type": null,
"actor_id": <userId>,
"target_id": null,
"app_data": [
],
"action_links": null,
"permalink": "",
"post_id": "<postId>",
"viewer_id": <userId>,
"created_time": 1369109320,
"updated_time": 1369109320,
"source_id": <userId>,
"message": "",
"description": "<user name> likes a status.",
"attachment": {
"description": ""
}
}
Which status?
Or:
{
"type": null,
"actor_id": <userId>,
"target_id": null,
"app_data": [
],
"action_links": null,
"permalink": "",
"post_id": "<postId>",
"viewer_id": <userId>,
"created_time": 1367029922,
"updated_time": 1367029922,
"source_id": <userId>,
"message": "",
"description": "<user name> likes a link.",
"attachment": {
"description": ""
}
}
Which link?
Do I need to do a multi-part query to get the extra data from a different table?
Why is the target_id always null?
This is a long standing bug, that hasn't been fixed for reasons unknown
https://developers.facebook.com/bugs/522743067756848
There is actually no efficient way to do it in the API.
<postId> = <userid_pId>
The way via Facebook UI would be https://www.facebook.com/userid/posts/pId
I've opened a new bug report but I highly doubt it will be fixed.
https://developers.facebook.com/bugs/648986871793611

Get more detail from Facebook Notifications?

I'm writing an app that gathers info from a users Facebook notifications. Using the Graph Explorer, I request:
me/notifications?include_read=true
and this returns a bunch of data. Each item is a notification item you would see when logging into Facebook. For example (ID/names changed slightly):
{
"id": "notif_630262196_168132987",
"from": {
"name": "John Bloggs",
"id": "822724665"
},
"to": {
"name": "Dermot Bloggs",
"id": "680265196"
},
"created_time": "2013-01-23T22:58:28+0000",
"updated_time": "2013-01-23T22:58:28+0000",
"title": "John Bloggs commented on your link: \"Goodbye Great Barrier Reef. Goodbye...\"",
"link": "http://www.facebook.com/<removed>/posts/330788937030559?comment_id=1702155",
"application": {
"name": "Links",
"id": "2309869772"
},
"unread": 0,
"object": null
}
The notification is in relation to a comment, but the "title:" field gets truncated if it is too long.
Is there a clean way I can programmatically access the comment directly, so I can get all the text, even if it is a 1000 character comment?
Thanks! :-)
You should be able to get the comment by parsing the link field and querying:
/330788937030559_1702155
or
/POSTID_COMMENTID
When I tested this on my account, I am getting a comments object in the returned data, with the full text of the comments. I've got most permissions enabled in my Graph API. I suspect adding read_stream to the permissions is what will give you this data.
You can avoid parsing! I've been doing a lot of experimentation with notifications and getting what I've called the 'source' object (the source object being the Facebook Graph Object from which the notification originates). Unfortunately, I can't find any documentation on how exactly this mechanism works, but if your app has been granted a lot of permissions, the "object" field which in the JSON you posted is null will actually be populated with the 'source object'. Instead of just "object" : null it will look like this:
"object": {
"id": "587140489_588632201147717",
"from": {
"name": "Dave Rodríguez",
"id": "587140489"
},
"message": ":D ",
"picture": "https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-prn1/632550_478955408819349_478954732152750_60483_1892_t.jpg",
"link": "https://www.facebook.com/photo.php?v=478954732152750",
"source": "http://video.ak.fbcdn.net/hvideo-ak-prn1/v/754708_478955348819355_1792301950_n.mp4?oh=c7295ccfc3773f24de931e4c29f512ce&oe=513F1728&__gda__=1363127340_9302c108824176369427a0b17491b800",
"name": "¡¡¡EL SECRETO DE LA CHANCLA!!!!",
"description": "EL SECRETO DE LAS MADRES, EL MÁS UTILIZADO EN TODAS LAS GENERACIONES, VÉALO USTED MISMO Y ((COMPARTA))!",
"properties": [
{
"name": "Length",
"text": "1:13"
}
],
"icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/587140489/posts/588632201147717"
},
{
"name": "Like",
"link": "https://www.facebook.com/587140489/posts/588632201147717"
}
],
"privacy": {
"value": ""
},
"type": "video",
"status_type": "shared_story",
"object_id": "478954732152750",
"application": {
"name": "Video",
"namespace": "video",
"id": "2392950137"
},
"created_time": "2013-03-10T20:45:20+0000",
"updated_time": "2013-03-10T20:45:20+0000",
"likes": {
"data": [
{
"name": "Adrian Guerra Cuenta Verificada",
"id": "674364748"
}
],
"count": 1
},
"comments": {
"count": 0
}
}
I hope somebody more knowledgeable than me can tell us exactly what permissions we need to see this field populated. I'd figure it out myself but there are so many permissions that brute-forcing the SUM(nCk(77,k),k,1,77)=151115727451828646838271 possible combinations of permissions would take a very long time.