Retrieve posts I liked on facebook - facebook

I am making some fb open graph query of the form me/posts and I get the right result.
However I also get stuff like,
{"story" "MY_NAME likes a status", "id" "MY-FACEBOOK-ID_OTHER-MISTERIOUS-ID"}
Since I am human I guessed that "OTHER-MISTERIOUS-ID" should be the ID of the status I liked, so I try to fetch such status, always on open-graph with a query like
/OTHER-MISTERIOUS-ID, but this query return empty.
Someone else faced the same problem ?
What they come out with ?

The post id cannot be changed. After retrieving the posts, you have to retrieve the likes for each post like this:
https://graph.facebook.com/POST_ID/likes?limit=10000&format=json&access_token=ACCESS_TOKEN
You will get response like this:
{
"data": [
{
"id": "FACEBOOK_ID OF THE USER WHO LIKED THE POST",
"name": "NAME OF THE USER"
}
],
"paging": {
"cursors": {
"after": "******",
"before": "***"
}
}
}
so you will get all users who liked a particular post, and you can easily compare the ids to find the posts that you liked.

Related

Facebook Graph API get comments from Comments Plugin

I'm trying to get all comments from Facebook Comments Plugin running in my application.
Here's a step by step of what i have done
https://graph.facebook.com/{myUrl}
{
"share": {
"comment_count": 43,
"share_count": 1695
},
"og_object": {
"id": {myObjectID},
"description": {myDescription},
"title": {myTitle},
"type": "website",
"updated_time": "2018-05-28T21:50:37+0000"
},
"id": {myUrl}
}
https://graph.facebook.com/{myObjectID}/comments?access_token={pageToken}
{
"data": [ ],
"paging": {
"cursors": {
"before": {beforePointer},
"after": {afterPointer}
},
"next": {nextUrl}
}
}
So despite comment_count = 43, data field is empty.
It's also weird that a {nextUrl} is given although not showing any results.
Haven't found nothing about this in the recent update due to GDPR.
Any ideas?
The graph API has changed recently due to privacy and GDPR concerns.
To get all comments for a page or user first you need to make a call to get all your posts and then make a call for each post to get comments.
Please view the following example end to get all the posts and then post_ids (the call is similar for user posts).
https://graph.facebook.com/v3.2/{pageId}/posts?access_token={accessToken}
post_id looks something like this - 5704324444475_570454233326 and is in the id field of each returned post.
Then call the get comments endpoint from the graph API using the ID(s) returned by the first endpoint.
https://graph.facebook.com/{post_id}/comments?access_token={accessToken}&summary=true
You'll need to make a separate call for each posts to get that post's comments.

Permissions to Read Likes via Graph API

Since the REST API has gone, I need to find another way to read the likes for pages of our webapp.
According to the Graph API docs, the following should return the likes for any object (such as a page):
https://graph.facebook.com/v2.6/{PAGE-ID}/likes?summary=true
Oops, An access token is required to request this resource. Turns out, instead of a real token, you can also build an ad-hoc token witht the app ID and secret:
https://graph.facebook.com/v2.6/{PAGE-ID}/likes?summary=true&access_token={ID}|{SECRET}
The above returns a JSON payload, however, it's empty even though I'm trying this with a page having almost 200 likes:
{
"data": [
],
"summary": {
"total_count": 0,
"can_like": false,
"has_liked": false
}
}
Maybe a permissions problem? The app domain and the page URL domain are identical.
Big thanks for any hints to solve this riddle!
It does work with a simple App Access Token too, but i assume you get the wrong idea about that endpoint. There is no way to get the "Page Fans", you can only get "other Pages the current Page likes" with it. Just try this with your App Access Token:
https://graph.facebook.com/bladauhu/likes?access_token=APPID|APPSECRET
It should return the following JSON:
{
"data": [
{
"name": "FKK Scibes Skulls",
"id": "1391253501090151"
},
{
"name": "Dodgeball Austria",
"id": "387249994631552"
},
{
"name": "Turbojugend Scibes",
"id": "105248832848054"
},
{
"name": "HYDRA! Das endgute Satiremagazin.",
"id": "167084486537"
},
{
"name": "VLÜ Hydra",
"id": "113680962002559"
}
],
"paging": {
"cursors": {
"before": "MTM5MTI1MzUwMTA5MDE1MQZDZD",
"after": "MTEzNjgwOTYyMDAyNTU5"
}
}
}
More information about Tokens:
http://www.devils-heaven.com/facebook-access-tokens/
https://developers.facebook.com/docs/facebook-login/access-tokens/
https://developers.facebook.com/docs/apps/changelog#v2_6_changes:
The likes field on the Page node has been renamed to fan_count
As luschn said in their answer, likes are the other pages liked by that page; if you want to get the number of people that like the page itself, you need to request fan_count.

Is it possible to get user detailed using facebook API V2.6

I am using the "taggable_friends" api to get the list of all friends then uses the user ID (a string of 110 chars) to get user detailes like this:
FB.api('/' + gFriend.id , 'GET',{},
function(response) {
console.log("response",response)
});
In the result I get an error
(#803) Some of the aliases you requested do not exist: {The user Id I have submitted}
Did FB blocked user details API in version 2?
taggable_friends if for tagging only, you can´t use it for anything else and you don´t get a User ID. You only get a "tagging token" that can only be used for tagging. If you just want to create a "friend pic collage", you need to use /me/friends instead. Of course you will only get friends who authorized your app with the user_friends permission.
[from comments] I want to show friend pic collage
The taggable_friends endpoint does return URLs of the friend’s profile pictures already.
You get a data structure like this,
{
"data": [
{
"id": "AaKYNqeDaP…",
"name": "Foo Barski",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/…"
}
}
},
{
"id": "AaKBGEbAAvYU…",
"name": "Some One Else",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/…"
}
}
},
So all you need to do is use those URLs provided in the picture structure.

How to get the user data of a facebook group post? The original poster

I have gotten a post object from the Facebook Graph API as such:
GET/v2.5/142679255268_10153887281355269
Which returns an object like so:
{
"created_time": "2016-03-25T03:28:50+0000",
"message": "Whats up everybody, I am here now",
"id": "142679255268_10153887281355269"
}
How can I get the profile of the user who posted this?
I have looked through the documentation and couldnt find anything, but I know its possible.
This would work for the Post item:
/142679255268_10153887281355269?fields=from
It returns the following JSON:
{
"from": {
"name": "Bhumi Patel",
"id": "10153245821277822"
},
"id": "142679255268_10153887281355269"
}
More information: https://developers.facebook.com/docs/graph-api/reference/v2.5/post/
Edit: For data privacy reasons, you may not get the name of the user anymore.

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