How can I get a facebook users photo comments - facebook

Currently when I look at my posts via the GraphAPI:
https://graph.facebook.com/me/posts/
Some posts have their "story" parameter truncated like this (note the ... after the word toe,):
{
"id": "xxxxxxxxx_yyyyyyyyyyyyy",
"from": {
"name": "zzzzzz",
"id": "1234567890"
},
"story": "\"those things pivot at the toe,...\" on XYZ's photo.",
"story_tags": {
"39": [
{
"id": 11111,
"name": "XYZ",
"offset": 39,
"length": 22,
"type": "user"
}
]
}
The above is a comment on a photo within facebook, so the graph api ids=http://.... approach that I have seen elsewhere on SO does not work. When I try to pass in the id to the comment table via FQL I get no data returned. I have all the appropriate permissions in the access token.
Overall what I am trying to achieve is a way to get everything a user has written/typed on facebook recently, so I need:
1.status updates - achieving this via:
select time, message from status where uid=me()
2.check ins - still working on this
3.comments on photos or working on other peoples status - still working on this and the reason for this post

Related

Facebook Graph API apprequests node doesn't return "from"

Moving from FQL to Graph API, I found that the V2.2 Graph API apprequests node returns inconsistent responses.
https://graph.facebook.com/v2.2/<id>/apprequests
sometimes returns JSON with the "from" field and sometimes not.
The correct JSON is:
"application": {
"name": "Myapp",
"namespace": "My NS",
"id": "123456"
},
"created_time": "2015-03-16T19:34:00+0000",
"data": "invite",
"from": {
"id": "111111",
"name": "Sender name"
},
"message": "Come and play!",
"to": {
"id": "99999",
"name": "Recipient"
},
"id": "123_456"
}
However, the "from" field in the JSON is sometimes missing (even when requesting it specifically in the "fields" parameter).
When using FQL, I always get the sender_uid field (with the same app token and same user):
SELECT request_id, app_id, recipient_uid, sender_uid FROM apprequest
WHERE app_id = <appID> and recipient_uid=<FBID>
Can anybody explain the mystery?
Facebook's response after investigating this bug: This is by design. There are certain privacy restrictions on Graph API which didn't apply to the deprecated FQL.
We investigated this on our end and found that this happens when the user blocked the application or completely removed Facebook's third party integration.

Facebook Graph API Get Comments outside of Wall

I have been learning how the Facebook Graph API works for a while and managed to get the info out of the "me" , "me/likes" and "me/posts" edges,
My question is in regard to the "me/posts" edge; it retrieves all the posts on the user's wall only not the posts/comments he made on another page and or a friends wall, all i get is a "type": "status" JSON node with no actual "message": "" node in the JSON entry saying "XYZ commented on a status."
Example:
{
"id": "<USER_ID>_<POST_ID>",
"from": {
"id": "<USER_ID>",
"name": "XYZ"
},
"story": "XYZ commented on a status.",
"story_tags": {
"0": [
{
"id": "<USER_ID>",
"name": "XYZ",
"offset": 0,
"length": 3,
"type": "user"
}
]
},
"privacy": {
"value": ""
},
"type": "status",
"created_time": "2014-11-11T22:18:25+0000",
"updated_time": "2014-11-11T22:18:25+0000"
}
As you can see there is no "message": "value" node included in the JSON returned its just informing me that he made a comment but i need the value or the message of that comment !
Now, failed attempts i have gone through so far includes:
1. Requesting <PAGE_ID/FRIEND_ID>/posts: I'm unaware of the
PAGE_ID/FRIEND_ID with the information i have from the previous
JSON.
2. Requesting the <POST_ID> returned: As explained it
doesn't work and for my case a 100% of the time.
So is there an official way to know what the user wrote on fan page or on a comment he made on a friend's public wall through the Facebook Graph API or even the FQL API ?
Thanks.
This is a long standing bug in Facebook, probably older than two years.
https://developers.facebook.com/bugs/648986871793611/ https://developers.facebook.com/bugs/522743067756848/
Facebook doesn't seem interested in fixing this.
There is no official way to do this until Facebook fixes the incomplete data.

How to get realtime like count from a picture posted by my app?

I'm developing an application and what I want it to do is:
Post a poto on the user's wall
Get, in realtime, the number of likes that this post will recieve
The first problem I'm having is to get the likes count based on the post-id, this is my photo upload code:
FB.api('/photos', 'post', {
message: $user_submited_string,
url:'http://example/url/image.jpg'
}, function(response){
if (!response || response.error) {
//error handler
} else {
var posted_content_id = response.postid;
console.log(posted_content_id);
})
But when I put this posted_content_id variable into the Open Graph Debugger I won't get the number of likes in return:
{
"id": "1685033176_4107146412059",
"from": {
"name": "João Paulo Apolinário Passos",
"id": "1685033176"
},
"picture": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-prn1/548929_4107355417284_1018318871_s.jpg",
"link": "https://www.facebook.com/photo.php?fbid=4107355417284&set=a.4107146292056.1073741826.1685033176&type=1&relevant_count=7",
"name": "My Test App Photos",
"icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/1685033176/posts/4107146412059"
},
{
"name": "Like",
"link": "https://www.facebook.com/1685033176/posts/4107146412059"
}
],
"privacy": {
"description": "Public",
"value": "EVERYONE",
"friends": "",
"networks": "",
"allow": "",
"deny": ""
},
"type": "photo",
"status_type": "added_photos",
"object_id": "4107355417284",
"application": {
"name": "My Test App",
"id": "178883808932511"
},
"created_time": "2013-04-10T01:20:12+0000",
"updated_time": "2013-04-10T01:20:12+0000"
}
Which does not contain the like count of my picture. So the first question is: how to get the like count of the image that the user inserted?
The second thing is that, after getting the number of likes, I want to rank them. To do that, I thought about storing them into a database and set a cron job to check new posts and update the rank with new posts. When I was looking how to do that I came across the "Realtime Updates" section of the Facebook Developers Documentation. But for me it's not clear if I can get this like count in real time and how. And that is my second question: Can I get the number of likes of an image in realtime, using native "Realtime Updates"? And if that's not possible, how to create my own counter? Extended token and cronjobs?
I'm asking this two questions in one because maybe the second question's anwser is also the first one. And the last thing I need to know: even if it's doable, doing something like that violates on someway Facebook Policies?
This is because you are querying for the Post Id, not the Photo Id.
When you upload the photo, a post is also automatically published on the feed of the user.
To read the Photo id, you must use the response.id property.
In your example the id of the photo is 4107146412059, you can derive it from the post id that is in the form <user-id>_<photo-id>, but don't count on it, since that can change in the future.
Doc on the Photo object in the Graph API documentation
Real time updates:
You can get real time push notification from Facebook when the User feed is updated:
but this would be overkill, since you'll get all the posts to the User feed, not only to your photo. Sadly, I think the only way is to poll for updates.
Other info on Real time updates: Facebook documentation

Facebook Ignore Graph API Page Posts Connection - Ignore Replies & Comments? Story vs Message

I'm pulling page posts from the Graph API, but I would like to ignore comments or replies.
So for instance:
{
"id": "115673336230_10151050684306231",
"from": {
"name": "New York Jets",
"category": "Professional sports team",
"id": "115673336230"
},
"story": "\"Well said, Michael. We know our...\" on [User's name removed]'s post on New York Jets's wall.",
"story_tags": {
"40": [
{
"id": ----------,
"name": ------------,
"offset": 40,
"length": 15,
"type": "user"
}
]
},
"type": "status",
"created_time": "2012-09-27T13:39:55+0000",
"updated_time": "2012-09-27T13:39:55+0000",
"comments": {
"count": 0
}
}`
There doesn't seem to be any piece of this response that I can use to filter a reply like this out other than the 'on User's Name post' bit in the story field.
I've noticed that all of the replies to comments appear without message data and with story data, but from the docs its unclear if this would be a reliable data point to filter against.
Is there a way to ignore comments/replies in the Page posts connection? Do all Page Posts (non comment replies) have data in the message field and never in the story field? That is, can I reliably ignore 'posts' that have no message? That have a story?
If you want more powerful filtering, you should look at querying the stream table with FQL.
The type field allows you to filter out posts based on what they are. Adding AND type != 247 will exclude comments from the data returned.
There might be a way to do this using the API by requesting the status_type field, but then you'll have to also manually request all other fields you want to display, and you'll still end up filtering them in your script.

Total friends who posted a Like or comment on the posts generated by app

I have been asked to come up with this metric. I'm not sure of the thinking behind it maybe that a facebook friend can comment more than once.
But i have looked through the post api docs and can't think of how i would measure it. I also looked through facebook insights and can not find anything. Any suggestions on how to measure this would be greatly appreciated.
You can get the number of likes for a post by using this FQL query
SELECT user_id FROM like WHERE object_id=" " // Object ID can be the post ID, that you received when a post is generated
You will receive the ID of all the people who have liked the post and you can check these ID's againts the ID's of the users friends. That way you can calculate the number of friends who have liked a certain post
Reference for like fql table
And similarly for comments you can use the following FQL query
SELECT comments,username,text,fromid FROM comment WHERE object_id=" " // Object ID can be the post ID
Similarly for the above query you will get the following data.
And you will easily get the ID of the user who has commented on the post and you can check it againts the users friends ID's.
{
"data": [
{
"comments": [
],
"username": "",
"text": "<3",
"fromid": 100003768234756
},
{
"comments": [
],
"username": "Anonymous User",
"text": "So True <3",
"fromid": 1770337460
},
{
"comments": [
],
"username": "Anonymous User",
"text": "That is the truth.......",
"fromid": 1165407722
},
{
"comments": [
],
"username": "",
"text": "<3",
"fromid": 537035838
},
{
"comments": [
],
"username": "Anonymous User",
"text": "So do u my love",
"fromid": 100003542817498
}
]
}
Reference for Comments fql table
Track every post you make, for every user.
When you make a post on Facebook via your app you get a post ID for every post, so you just need to keep a track of every post generated for each user, so that you can get the number of likes made on every post