Facebook Recommendation API not returning all fields - facebook

I am trying to implement the Facebook Recommendation API from the documentation, however in the sample they have just written GET v3.2/...?fields={fieldname_of_type_Recommendation}. What is the exact endpoint to be called to get the recommendations along with all its fields?
I used Ratings API earlier /v3.0/{page-id}/ratings but that does not returns the "Reactions Count" and "Comments Count" which I get for posts, I want that for Recommendations as well. Any help on how to get it?

The endpoint is
https://graph.facebook.com/v15.0/{page_id}/ratings?access_token={page_access_token}&fields=reviewer{id,name,picture.width(120).height(120)},created_time,rating,recommendation_type,review_text
the '...' should be replace with '{page_id}/ratings'

Related

How to access all draft campaigns with the Facebook marketing API?

I'm trying to list all of my draft campaigns using the Facebook marketing API. By default, it seems, only non-draft (published?) campaigns are listed when calling
curl -i -X GET \
"https://graph.facebook.com/v12.0/act_12345/campaigns?fields=id,name&access_token=<mytoken>"
When looking at the code of the facebook-python-business-sdk, there are multiple references to unpublished content type, which makes me think that there should be a way to list all unpublished campaigns. So my question is how can I list all campaigns, published and unpublished?
I know this question is a duplicate (see here, here, and here) but I'm asking it again since it has not been answered and I'd like to put out a bounty for a helpful response.
I believe the only way to get draft campaigns is below:
You should get all addrafts. On my account I have only 1 addraft that contains all draft campaigns, but maybe you can have more. URL for getting addrafts:
https://graph.facebook.com/v12.0/act_<ad_account_id>/addrafts?access_token=<access_token>&fields=name,ad_object_id,id
Now you can get addraft_fragments. You can see all draft fragments of your ad_account (campaigns, adsets, ads), but you can easily find here what you want. URL for getting addraft_fragments:
https://graph.facebook.com/v12.0/<addraft_id>/addraft_fragments?access_token=<access_token>&fields=name,id,ad_object_id,ad_object_type,budget,ad_object_name,values

Difference in Engaged Users (Facebook page) and Engaged Users (Insights API)

We have a tool connecting with the Facebook Insights API to grab various metrics (Likes, Comments, etc).
One such metric is the Lifetime Engaged Users.
However, we've looked at many FB pages (not going through the API) and the insights numbers seem to be different.
I have used the Graph Explorer to check if there is an error in our request, and this is not the case. For example, in one case, the call returns "13480".
Here is the screenshot from the Insights page:
FB Insights Page
I may not be checking at the correct numbers, but can someone help me out?
I would like to figure out how I can find this particular metric, other than using our tool or using the Graph Explorer.
Thank you!
Try this: go recheck your call to API, remove that S from "metricS=metricName".
I met this problem today, and find that there are two ways to get object insight data:
object-id/insights/metricNameA,metricNameB
object-id/insights/?metric=metricNameA,metricNameB
I happened to use the 2nd way, and wrongly typed metricS instead of metric, which led to return an array of data for all metrics, and my code data[0].values[0].value therefore got the first metric in that array which is "post_story_adds_unique", if you have same mistake as mine, that 13480 could be this 1st metric return by default from FB.

Facebook Insights - Post Details

In the "Posts" section of Facebook Insights, you can click on your latest posts and get detailed information about them:
I'm trying to recreate this data in a web application, using the Facebook SDK for .NET. I have found most of these numbers through Facebook's Graph API, e.g:
.../v2.3/(page-id_post-id)/insights/post_impressions_unique/lifetime
.../v2.3/(page-id_post-id)/insights/post_stories_by_action_type/lifetime
.../v2.3/(page-id_post-id)/insights/post_consumptions_by_type/lifetime
.../v2.3/(page-id_post-id)/insights/post_negative_feedback_by_type/lifetime
...except the post content and the numbers marked in red. Using Fiddler, it looks like Facebook fetches these values from a URL outside the Graph API:
https://www.facebook.com/ajax/pages/insights/view_story/...
However, that URL is only accessible if you're logged in to Facebook. So, the question is:
Given an access token, can my (server-side) web application somehow get the post content, or at least the missing numbers? Preferably using the Facebook SDK, but any solution will do.
Update:
As #CBroe points out, simply querying the post id itself gives you enough info to recreate the post content:
.../v2.3/(post-id)?fields=name,message,picture,link
So, the last piece of the puzzle is to get the missing numbers. "Likes - On Post" can be found by querying the post's /likes with a summary:
.../v2.3/(page-id_post-id)/likes?limit=0&summary=true
..but "Comments - On Post" and "Shares - On Post" are trickier.
Querying .../v2.3/(page-id_post-id)/comments does give the number of comments on the post, but doesn't include answers to those comments, which are included in the number 5 in the picture above. You can recursively query /comments on each comment id, but that would generate too many queries to be worth it.
One might think that querying .../v2.3/(post-id)/sharedposts could give you the number of times a post has been shared, but it only gives you a few of the shared instances (due to other users' privacy settings?)
to clarify, you're trying to get the number of likes, comments, and shares.
Likes [post_id]/likes?summary=True&limit=0
NOTE: You can also call it when calling the post fields [post_id]?fields=id,likes.summary(true).limit(0)
Comments [post_id]/comments?summary=true&limit=0
NOTE: comments edge has a param filter https://developers.facebook.com/docs/graph-api/reference/v2.3/object/comments which may be why you see different numbers
NOTE: You can also call then when calling the post fields [post_id]?fields=id,comments.summary(true).limit(0)
Shares [post_id]?fields=shares
the sharedposts edge is empty b/c you don't have "read_stream" permission for the user's posts, https://developers.facebook.com/docs/graph-api/reference/v2.3/object/sharedposts#readperms
Edit (by OP):
Adjustments to get the same numbers that are presented in the "Post Details" popup:
Comments - On Post: (page-id_post-id)/comments?filter=stream&summary=true&limit=0
Using only post-id without prepending page-id gives the same result, but you also get a debug message saying "...actual number of results returned might be different depending on privacy settings."
Shares - On Post: (post-id)/sharedposts?fields=id
Don't prepend page-id here - that yields an empty result set.
Sadly, ?summary=true doesn't work, so I used the fields filter just to reduce the amount of data.
The suggested (post-id)?fields=shares gives a different number which seems similar to the insights numbers, but doesn't add up to any of them.

Get the comment of a specific User- Facebook API

I want to get the list of comments made by given user through Facebook Graph API.
I haven't found any direct way to get lists of comments. So, I tried to find them through my feed, but it's returning all feed posts. Can we filter other posts where I have not commented?
I tried various queries as below, but could not get exactly what I need.
/me/feed?fields=comments?fields=from?name="my_name",message
/me/feed?fields=comments.fields(from.name("my_name"),message)
I need either (1) list of all comments by me or else (2) lists of posts which I have commented on, filtering out all other posts.
How can we do this?
There's no way to filter via the Graph API. Basically what you want to achieve is IMHO not really possible.
What you could theoretically do is use the comment FQL table, but the field you'd need (fromid) is not indexable: https://developers.facebook.com/docs/reference/fql/comment/ So this could be tough.

Get page_impressions from Facebook API

Using the Graph API Explorer, I am trying to obtain the page_impressions metric (as described in the Facebook API Insights Documentation) for one of my pages. The actual value that I am looking for is the "Weekly Total Reach" number, found on the Facebook Insights page (https://www.facebook.com/userID?sk=page_insights).
What I've tried under Graph API:
userID/insights/ - Gives some good info, but nothing about
page_impressions
What I've tried under FQL Query:
SELECT metric, value FROM insights WHERE object_id=userID
AND metric='page_impressions' AND
end_time=end_time_date('2012-12-26') AND period=period('week') - This
returns an empty data set.
This same question (or very similar) has been asked a few times on stackoverflow, but I could not find an answer.
Turned out I was really just having issues with my Auth Token. When I used the following Graph API call it worked just fine:
/[pageId]/insights (thanks to Oleg, for the correction on pageId)
This gave me all the info I needed, including the page_impressions. And if I wanted just the page_impressions data:
/[pageId]/insights/page_impressions