I am interested in getting post lifetime insights for a given page in a single request.
A previous issue did half the work: Get posts with insights from a single API call - Facebook Graph API
Which allows me to get the insights for all posts in a single request by doing:
/{page-id}/posts?fields=insights.metric(post_impressions_fan,post_engaged_users)
But these are not always lifetime insights, and I would like to specify period=lifetime for the sub object.
How can I in Facebook Graph API do such?
I tried:
Adding insights.period(lifetime) which errors with: "Field insights specified more than once. This is only possible before version 2.1"
Doing insights only once as insights{metric(post_impressions_fan,post_engaged_users),period(lifetime)} but that failed with "Expected end of string instead of \"(\"."
You can use this API call to get lifetime post insight:
{page_id}/posts?fields=id,name,type,shares,link,permalink_url,created_time,picture,comments.summary(true).limit(0),likes.summary(true).limit(0),reactions.summary(true).limit(0)&period=lifetime&limit=100
use pagination to get all the post since maximum limit we can set is 100.
Related
I'm using the delivery endpoints of the Facebook Marketing API (v3.2)
I've successfully got this one working:
/{AD_ACCOUNT}/delivery_estimate
(Note, as usual the docs are misleading and you have to use the prefix act_ for it to work)
I can't get this to work:
/{AD_SET}/delivery_estimate
(Ad sets are groups of ads within a campaign).
If you just supply the number on its own, it fails, as you'd expect, with:
Cannot determine the target object for this request. Currently
supported objects include ad account, business account and associated
object.
I've tried a few variations - ad_, adset_, ad-set_, ad_set, adsetid_ etc. - none of which work.
Anybody know what it is? I've not found anything in the API docs, so if anyone does have a Facebook URL that explains it…
Answer - there's no prefix or special way to write ad set IDs. I'm unclear why it wasn't working before.
You can use this to get a list of adsets for the account (as an array in 'data'):
https://graph.facebook.com/v3.3/act_0000000000/adsets
Then you just supply the ID on it's own after the API version number:
https://graph.facebook.com/v3.3/12345678901234567/delivery_estimate?targeting_spec...
I wanted to make a facebook API request that will post a message to page that I am admin of. Here i found out how can i do that but after trying it out in facebook graph api explorer with this scheme:
graph.facebook.com/page-id/feed
?message=Hello&access_token=your-access-token"
assuming I have a developer account linked to my page and publish_pages and manage_pages permissions are enabled and page-id and acces-token are replaced with my real ones. The problem is that I get a response of latest post on that website, the same as if I would write just graph.facebook.com/page-id/feed and there is no new post on my page.
I dont know if the recent facebook API update removed or modified that or if its just not possible.
trying it out in facebook graph api explorer with this scheme
graph.facebook.com/page-id/feed?message=Hello&access_token=your-access-token
You are making a GET request here - and GET is for reading data, not creating it.
Creating data requires a POST request. So you can either switch the request method from GET to POST via the dropdown there, and then click + Add parameter to add your parameters and values;
or you can add &method=post to the end of your GET request query string here - that is a way the API offers to explicitly overwrite the request method in environments, where you can only make GET requests.
I am trying to collect visitor posts from the page of a political party. Even though I can collect the statuses posted from the political party itself, when I request a token for visitor_posts, I get the following error message:
{
"error": {
"code": 1,
"message": "Please reduce the amount of data you're asking for, then retry your request"
}
}
When I then add a limit, I get the same error message, even when I set the limit as 1, 10, or 100. After googling around, people then suggested to add a since/until, since there would be such a high number of visitor posts. However, when I tried that, it also did not work. Has Facebook changed its API to block this kind of collection?
Thanks in advance.
The endpoint [page]/visitor_posts is still functioning correctly, though there are prerequisites for calling it. Assuming you are a page management app, your access token must have manage_pages and pages_show_list scopes.
It isn't necessary for you to use a page access token to make this call and the request can be made with a user access token. It's also not necessary to have any permissions or specific roles on the page you are querying.
Since you are having issues with too much data being returned, although including a limit didn't help, you may help their query engine out by providing a since parameter. This is a filter for posts since a certain unix (seconds) timestamp, example using 12:00 AM UTC today:
[page]/visitor_posts?since=1523318400
I am able to get all the page posts that can be promoted via the endpoint given at https://developers.facebook.com/docs/marketing-api/campaigns/objectives#connection_objects
eg query:
https://graph.facebook.com/v2.5/[PAGE-ID]/promotable_posts?fields=id&is_published=true&access_token=[TOKEN]
but how do I get all the posts that are already promoted? I am unable to find anything on the FB API docs.
There is no simple way to do this as there is no association between a post and an ad.
The easiest way to do this would likely be to request all creatives for an account, along with their object_story_id:
/<VERSION>/act_<ACCOUNT_ID>/adcreatives?fields=object_story_id
And then request all ads within the account along with creative and reference whether there is a match:
/<VERSION>/act_<ACCOUNT_ID>/ads?fields=id,creative
This is confusing. So just to clarify:
REQ #1: To fetch basic stats for a URL, you send GET request to:
http://graph.facebook.com/?ids=http://some.com
(alternatively, FQL can be used to fetch stats for a URL, but that doesn't return the OpenGraph Object)
REQ #2: To fetch comments for a URL, you do a GET:
http://graph.facebook.com/comments/?ids=http://some.com
REQ #3: To fetch likes for a URL, you GET:
http://graph.facebook.com/likes/?ids=http://some.com
But how do you comment on / like a URL programmatically?
I guess, likes can be created using Open Graph API, right?
https://graph.facebook.com/me/og.likes?object=1234
where 1234 is the OpenGraph Object ID of an article (as returned by REQ #1).
But this requires an approval process, the like action has to be approved by Facebook.
Is there a better way to do this? Can I use for example the Graph API for all these things?
My goal:
Currently I'm using the Facebook like button and comments plugin to create likes and comments. But these use the JS SDK, which is huge, and they generate a lot of external requests. I wanna get rid of them and just send an AJAX request to my server, which would then asynchronously talk to Facebook, and it would post the Like / Comment.
Is this possible?
Thanks in advance!
I read through the Facebook docs briefly and I don't believe you can do this other than the way you indicated with authenticating.
You should also take a look at this thread: 'Like' a page using Facebook Graph API
You would need to authorize every single user before he would be able to like something, and you would need to go through a review process on Facebook. And i am pretty sure you would not get the required permissions approved just because you want to get rid of the JavaScript SDK overhead, to be honest.
The Social Plugins are asynchronously, so the overhead for downloading the SDK is irrelevant as it happens in the background and it is non-blocking.
I have an idea, to do this. You can use long term access token, Once you login you receive short term token. After receiving short term token you need to request your long term access token. Save that token in DB or file.
Then you can use Graph Api, to make requests. This will eliminate the need for access requirement every time you request api.
Just use access token you saved before.
Refer this documentation from Facebook for further clarity.
https://developers.facebook.com/docs/facebook-login/access-tokens
Happy Coding!
Atul Jindal