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
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 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.
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
I would like to show the posts from my Facebook page in another website using Graph API:
https://graph.facebook.com/[pageID]/feed?access_token=[accesstoken]
My question is, which access token should I use?
I have tried using my App Token, but I feel like I should be using other access tokens, how would I be able to obtain another Access Token?
Depending on your use case there a three different options when it comes to the question of which access_token to use:
Use any sort of access_token to get all posts that are public
Use an user access_token to get all posts visible to the user the token belongs to
Use a page access_token to get all posts
As far as I understand you, you want to get all posts from your page, regardless of any restrictions that may apply to a user that is viewing the feed (example: age restrictions, country restrictions). In that case use the page access_token for the page you want to get the feed from.
You can get the page token by calling /me/accounts [1], look for the page object and get the access_token for that page.
You can also read about it in the Graph API documentation [2] for pages.
[1] https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Faccounts&version=v2.0
[2] https://developers.facebook.com/docs/graph-api/reference/v2.0/page/feed#read