I am trying to figure out if the following is possible through the various Facebook APIs:
Create a Post on a Page through the API (I know that's possible:)
Boost that Post through the Ad API (I read that it's possible but I
can't really find the API that would let me do that. if you know it,
please point it out! Thanks!)
Once boosted, is there a way I can pull the boosted post information
from the original post? I assume that once boosted, the boosted post
is a different version of the original post, right?
I can get post stats through the Insight API and I can get boosted
post stats through the various Ad stats API. Do the post stats only
apply to the post and the boosted post stats only apply to the
boosted post or are they all one set of stats that applies to both?
Thanks in Advance!
Everything you are looking to do is available trough both the Graph API and the Marketing API.
1) Yes this is possible, as you pointed out. You can read more here
2) I would suggest that you read through the Marketing API doc I linked above to find out the full structure of an ad. But in short, an ad is split into the following 4 objects:
Ad Campaign: This is simply a grouping of Ad Sets which all have a similar business purpose as defined by the campaign objective.
Ad Set: An ad set is a group of ads that share the same daily or lifetime budget, schedule, bid type, bid info, and targeting data.
Ad Group: An ad object contains the data necessary to visually display an ad and associate it with a corresponding ad set. Each ad is associated with an ad set and all ads in a set have the same daily or lifetime budget, schedule, and targeting. Creating multiple ads in each ad set will let us optimize their delivery based on variations in images, links, video, text or placements.
Ad Creative: An ad creative object is an instance of a specific creative which is being used to define the creative field of one or more ad groups.
3) When a post has an ad created based on it there is not "duplicate" post created for the purpose of the Ad. If you want to only get paid/boosted information on the post then the best way to do this would be using the Ads Insights API.
4) When you pull stats from the insights API you will see metrics with 'paid' appended to them, for example 'post_impressions_paid'. This will return you the number of paid impressions (i.e. from an ad) but it will not give you any information on which ad caused those impressions. The Ad Insights API's will only return impressions, likes, comments etc caused by the ads that serve the post, they will NOT return organic actions.
Here is a quick run down of cURL commands that will create a campaign to boost a Post, but before trying them I would fully read the Marketing API docs so you understand whats happening.
// First we need to get the Ad Account from a user
curl https://graph.facebook.com/{USER_ID}/adaccounts&access_token={TOKEN}
// Now we can create our Ad Campaign. Response: {"id": "CAMPAIGN_GROUP_ID"}
curl \
-F 'name=my campaign group' \
-F 'campaign_group_status=PAUSED' \
-F 'objective=POST_ENGAGEMENT' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/adcampaign_groups
// Using the Campaign Group ID we can create an Ad Set. Response: {"id": "AD_SET_ID"}
curl \
-F "name=My Adset" \
-F "bid_type=CPC" \
-F "bid_info={'CLICKS': 500}" \
-F "campaign_status=ACTIVE" \
-F "daily_budget=2000" \
-F "campaign_group_id=<AD_CAMPAIGN_ID>" \
-F "targeting={'geo_locations':{'countries':['US','GB']}}" \
-F "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/adcampaigns"
// Before we create an Ad Group, it is recommended to create an Ad Creative.
// Response: {"id": "CREATIVE_ID"}
curl \
-F "name=sample creative" \
-F "object_story_id=<POST_ID>" \
-F "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/adcreatives"
// Now that we have the Creative ID we can use that to create the final piece
// of the puzzle, the Ad Group. Response: {"id": "AD_GROUP_ID"}
curl \
-F "name=my ad" \
-F "campaign_id=<AD_SET_ID>" \
-F "creative={'creative_id':<AD_CREATIVE_ID>}" \
-F "adgroup_status=PAUSED" \
-F "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/adgroups"
Related
I am trying to get the campaigns list from the Graph API Explorer. I'm using the request found at https://developers.facebook.com/docs/marketing-api/reference/ad-account/campaigns/.
GET /v2.8/{ad-account-id}/campaigns HTTP/1.1
Host: graph.facebook.com
I'm' business manager and admin of the page used for ads. I found the AD_ACCOUNT_IDs using the following request on the Graph API Explorer.
GET /v2.8/me/businesses HTTP/1.1
Host: graph.facebook.com
I choosed the one which had the higher privileges.
The error reported when submitting the first request for campaigns is:
{
"error": {
"message": "Unsupported get request. Object with ID '1015359838XXXXXX' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"fbtrace_id": "DLyfwGbM8fi"
}
}
What's wrong?
Thanks in advance,
Mattia
#Ryan's answer saved my day. It may sound stupid/silly but I was doing this mistake and I was just stuck at it.
Going through the FB docs for using the Marketing Apis.
I was trying to build the custom audience, this is how the curl request looks like -
One of the basic things to keep in mind while using the Marketing API is, almost all the APIs ask for these two things -
1) ACCESS_TOKEN
2) AD_ACCOUNT_ID
For people who are just starting with the FB Marketing API or somehow stuck in finding these values, I will just tell you how to get these values, so that you don't have to waste your time as I did.
So for getting the ACCESS_TOKEN, go to your app dashboard then click Add Product and then select Marketing API. Once you added the product, this is how the screen should look like -
Now just check the permissions and click on the Get Token button, a token would be generated. Just copy the token in some file and save it.
Now for getting the AD_ACCOUNT_ID value, just go to the Adverts Manager page -
The number that is written inside the red box in you Adverts Manager page is your AD_ACCOUNT_ID.
The final step would be to go back to you app dashboard again, Settings > Advanced
Click on Ads API and then enter the AD_ACCOUNT_ID here. Thats it, you have finished the Access and Authentication process for using the marketing API via your App.
Now comes the part where I was doing the silly mistake. The curls request looks like this -
curl \
-F 'name=My new CA' \
-F 'subtype=CUSTOM' \
-F 'description=People who bought from my website' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/customaudiences
First I replaced ACCESS_TOKEN with its value.
Then instead of replacing only the <AD_ACCOUNT_ID> I replaced the whole string act_<AD_ACCOUNT_ID>, with the AD_ACCOUNT_ID value.
So I was getting this error while making request to the API which was -
{"error":{"message":"Unsupported post request. Object with ID '120574219' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api","type":"GraphMethodException","code":100,"fbtrace_id":"YsSvKKwgLMQ"}}
I don't know why I made this mistake but I am sure this is one of the common mistake others are doing too. Since the response from FB was misleading, I wasted a lot of my time in understanding and reading on the API permissions and authentications.
Hope this article was helpful and save your time.
I similarly was having problems trying to retrieve a list of all campaign IDs within an ad account.
I already am able to retrieve campaign data by ID, so I obviously have permissions already.
But the Facebook error message is misleading.
When retrieving an ad account (in order to then display its campaigns or whatever you want within it), you need to retrieve by its ID prepended with 'act_'.
E.g you could request /act_123456789000001234/campaigns instead of /123456789000001234/campaigns.
Thanks so much to #Jan Sommer at https://stackoverflow.com/a/39974857/470749.
I am trying to post an action using Facebook Open Graph API based on the Facebook documentation. When I do the following :
curl -X POST \
"https://graph.facebook.com/app/myNamespace:myAction" \
-F "access_token=$APP_TOKEN" \
-F "myObject=https://myhost.com/objectid"
I get the following error :
{"error":{"message":"(#200) Requires extended permission: publish_actions","type":"OAuthException","code":200}}
I have obtained a valid 'App Token' using this Faceboo documentation. The document states that actions can be published using App Tokens.
Btw, I am able to successfully post actions using user-access-token as follows :
curl -X POST \
'https://graph.facebook.com/me/myNamespace:myAction' \
-F 'myObject=https://myhost.com/' \
-F 'access_token=user-access-token'
Any Help is greatly appreciated.
You're trying to post to an Open Graph action as the app, which is not possible.
Unfortunately, there is no documentation to that explictly says this, but here is someone who tried to do the same thing.
If you read the documentation you posted, you'll see two main points. First, app tokens are for publishing information on the feeds of user's who have given permission to the app to do so, and app tokens are for some other basic "maintenance" type stuff for the app itself. There is nothing in there that support the idea that app tokens can be used for anything like posting regular Open Graph actions.
I would like to publish a status to a specific friend list (e.g. "family" or "best friends"). I can get the ID of the friend lists using the FB API, but I don't see a way to use this ID when publishing the status.
With a group, I can just publish to the group ID (https://graph.facebook.com/groupID/feed). But this doesn't seem to work for a friend list.
This seems to do the trick:
curl -F 'access_token=your_access_token' -F 'message=your_message' -F \
"privacy={'value':'CUSTOM','friends':'SOME_FRIENDS','allow':'your_list'}" \
https://graph.facebook.com/your_id/feed
I have question about the beta Open Graph stuffs.
The documentation I am looking at is this https://developers.facebook.com/docs/beta/opengraph/
I successfully define custom objects and actions. However, I cannot figure out how to link current user with other users.
For example, say I define a custom action 'kick'. I want the current user to be able to 'kick' one of his/her friends.
The closest object I can think of is 'profile', but when I pass user_id, 'http://www.facebook.com/profile.php?id=', or http://graph.facebook.com/, it does not work.
This is the requests I tried
POST https://graph.facebook.com/me/myapp:kick?access_token=abc&profile=http%3A%2F%2Fwww.facebook.com%2F123
POST https://graph.facebook.com/me/myapp:kick?access_token=&profile=123
POST https://graph.facebook.com/me/myapp:kick?access_token=abc&profile=http%3A%2F%2Fwww.facebook.com%2Fprofile.php%3Fid%3D123
POST https://graph.facebook.com/me/myapp:kick?access_token=abc&profile=http%3A%2F%2Fgraph.facebook.com%2F123
This is the response I get
{"error":{"message":"An unexpected error has occurred. Please retry your request later.","type":"OAuthException"}}
The profile given is for an external website. They call it external profile. Pretty misleading terms.
As you can see I used the following
curl -F 'access_token=TOKEN' \
-F 'profile=http://graph.facebook.com/zuck' \
'https://graph.facebook.com/me/MYAPP:kick'
And it gave the above.
I guess you can fill the external profile with meta info from the Facebook users and it will show alright (for example I can send the profile URL facebook.com/zuck instead), but it seems backwards, inefficient and not the intended usage.
For example feeding it my link.
curl -F 'access_token=TOKEN' \
-F 'profile=http://facebook.com/username' \
'https://graph.facebook.com/me/MYAPP:kick'
But the thing is ... I am not a musician.
It does though seem to look alright in aggregation view.
Which is interesting/weird since one of objects shown in this picture is a Facebook profile, so you would think they would give an example with Facebook profiles as objects.
Though they did say
We are now extending the Open Graph to include arbitrary actions and objects created by 3rd party apps and enabling these apps to integrate deeply into the Facebook experience
Which most likely means they want you to create arbitrary objects outside of Facebook.
Can you still link to other users?
Yes, but through tagging using tags=FacebookID1,FacebookID2 but it will be in the form of
phwd kicked a musician with Friend1 and Friend2 on [APP NAME]
I'd like to post a Link to Facebook using the Graph API, but I'd like to be able to avoid a thumbnail image. Facebook's web interface has a no-thumbail checkbox while posting an image; I'd like to simulate this from my own application.
I've tried specifying an empty string for both the source and picture arguments, but Facebook still fetches a thumbnail image for the specified link regardless.
For example, I've tried this, but a thumbnail image still shows up:
curl -F 'access_token=...' \
-F 'message=Link with empty source and empty picture' \
-F 'link=http://stackoverflow.com' \
-F 'picture=' \
-F 'source=' \
https://graph.facebook.com/me/feed
UPDATE: This support forum suggests that this is a bug with Facebook, and they suggest posting a 1x1 pixel clear image. I'd prefer a better workaround than this.
Since picture=0 no longer seems to work without throwing an error, here's another way, but it's a hack and not likely recommended. By skipping the picture argument and specifying a source argument that is a valid URL, but isn't an image, Facebook will render the post without the thumbnail. For example:
curl -F 'access_token=...' \
-F 'message=Link with empty source and empty picture' \
-F 'link=http://cnn.com' \
-F 'source=http://cnn.com' \
https://graph.facebook.com/me/feed
Facebook has now fixed this bug. Set picture to empty string or set picture=NULL, both should work now.
I talked with Facebook developers at F8 2011 and they agreed that this is a bug. I have filed this bug with Facebook in their new bug tracking system:
https://developers.facebook.com/bugs/231434760243248
If you want it fixed, upvote this question & answer!
Try using the value "0" for picture. This worked for us, it does show a gray bar next to the link information, but it doesn't pull in a default image and doesn't display the awkward whitespace when using a 1x1 pixel.
Hope this helps!
Now in June 2011 it seems the "picture=" parameter isn't required at all, and FB didn't pull one from the page either:
curl \
-F "message=test message, attempting to verify solution of SO problem" \
-F "name=StackOverflow" \
-F "link=http://stackoverflow.com/questions/4246170/how-do-i-post-a-link-to-facebook-without-a-thumbnail" \
-F "access_token=you_dont|reallythink|imgonnapostmyrealaccesstoken_doya?" \
"https://graph.facebook.com/11239244970/feed"
Result at SO's Facebook page: https://www.facebook.com/pages/stackoverflow/11239244970
It appears that if you specify a picture url where either the server is unreachable or the picture does not exist, the resulting post includes the grey bar as desired:
curl -F 'access_token=...' \
-F 'message=404 picture' \
-F 'link=http://example.com' \
-F 'name=Example' \
-F 'description=example.com is not about bbq' \
-F 'caption=example.com' \
-F 'picture=http://example.com/this/does/not/exist/1.gif' \
https://graph.facebook.com/me/feed/
For full disclosure however, I'm not using this solution in production because it seems hacky and I don't trust Facebook to allow this method to exist indefinitely.
put an invalid url image it's will "resolve" while the facebook not fix this bug.
the parameter is: "picture"
This had been disabled by Facebook and it's not a bug, it's by design as it's stated here by the FB team. They say they will remove the "No thumbnail" option from their site too, not just on the API. The thread I linked is the most recent (31 Dec 2015).
The only option that works now is by sending the field picture with the url to a 1x1 pixel image.