Facebook Ads API - How to create NewsFeed ads? - facebook

I can successfully create right column ads, but failed to create NewsFeed ads.
According to what I know, I should create type 27 creative first, and for this purpose, I need to provide parameter object_id and story_id. The first one is our company's facebook page, and the 2nd one is an unpublished post on that page.
To create a story, I used the codes below. I think it should be 'promotable_posts'. This is to create an unpublished post in the page so that it can be used in the newsfeed ad.
$api.put_connections('id_of_companys_fb_page', 'promotable_posts',
{
"message" => 'my_message',
"name" => "my_name",
"link" => "url_of_a_page",
"caption" => "my_caption",
"description" => "This is a longer description",
"picture" => "url_to_a_picture"
}
Unfortunately it always throws exception "type: GraphMethodException, code: 100, message: Unsupported post request. [HTTP 400] (Koala::Facebook::ClientError)".
If I change 'promotable_posts' to 'feed', then it works, but I cannot use the post id to create the ad, and I noticed that the id starts with 5xxx.. which is different from other manually created posts ids (starting with 1xx..) that worked. I even tried other types, but none works. I didn't find an example to create such post.
Any suggestions, even wild-guess, are appreciated.

Are you using the Ads API documentation?
Once you create the page post (via the /feed connection of the page) or have someone create it using the page management interface you create a type 25 or 27 ad using the post ID you retrieve from the API, or from the response of the API call you used to create the post itself.
The /promotable_posts endpoint returns the ID of any posts that can be turned into ads, it's a subset of the posts on /posts
A sample type 25 and 27 ad creative are included in the 'examples' section of the Creative Specs documentation
e.g. the type 27 example, modified to use a specific post ID, not the most recent post on the page:
curl \
-F "name=sample creative" \
-F "type=27" \
-F "object_id=<PAGE ID>" \
-F "story_id= <POST ID>" \
-F "access_token=_____" \
"https://graph.facebook.com/act_<ACCOUNT ID>/adcreatives"

Related

Post to Instagram via Facebook Graph API - unable to get the correct ig-user-id permission

I need to create a Meta application that posts scheduled content on the Instagram page of the company. The app is now in dev mode, and used through the Graph API and cURL.
After getting an Instagram user token on the Graph Explorer with all the required permissions (email, pages_show_list, ads_management, business_management, instagram_basic, instagram_content_publish, publish_to_groups, pages_read_engagement, pages_manage_posts, public_profile) and getting the ig-user-id through the GET /v13.0/me?fields=id,name API call, i make the container generation call, as described in the docs:
curl -i -X POST https://graph.facebook.com/{{ig-user-id}}/media?
image_url=https://{{image-url}}&caption={{text}}&access_token={{token}}
To which I get as a response:
Unsupported post request. Object with ID '{{ig-user-id}}' does not exist, cannot be
loaded due to missing permissions, or does not support this operation.
I tried to generate a Page token in spite of an User token, to use the Page ID in spite of the Used scoped app ID provided by the Graph API but the result has always been the same. One thing I noticed is, trying to get the IG user ID as described on the getting started page, point 5, to my request:
curl -i -X GET "https://graph.facebook.com/v13.0/{{page-id}}?
fields=instagram_business_account&access_token={{token}}"
The response is just {"id":"{{page-id}}"} in spite of the expected
{
"instagram_business_account": {
"id": "17841405822304914" // Connected IG User ID
},
"id": "134895793791914" // Facebook Page ID
}
So it appears it might be a permissions issue. Now, on the Business Settings for the business the app is related:
I'm listed under Users -> People as Administrator and Developer
I'm listed under Account -> Instagram Account -> People with all the permissions (Content, Community Activity, etc.) granted but messages (Impossible to assign - Available only on Instagram)
I'm listed onder Account -> Apps -> {{App Name}} -> People twice with all permissions granted.
Could anyone help me solve the issue? Thanks in advance.

Facebook and Parse: Code 251, Error: Parse::InvalidSessionError

I'm trying to set up a chrome extension that uses a Facebook Access token to login to Parse using the JS api. As a proof of concept I tried following the example here with curl, but when I put in my access_token and expiration_date, the POST call returns {"code":251,"error":"Parse::InvalidSessionError"}
Specifically, I'm calling this from the OSX shell.
curl -X POST
-H "X-Parse-Application-Id: [my app id]" \
-H "X-Parse-REST-API-Key: [my rest api key]" \
-H "X-Parse-Revocable-Session: 1" \
-H "Content-Type: application/json" \
-d '{
"authData": {
"facebook": {
"id": "[my id as a string]",
"access_token": "[my token as a string]",
"expiration_date": "2015-10-26T07:45:16.579Z"
}
}
}' \
https://api.parse.com/1/users
I've googled around a bit, including reading the following posts, but after changing my settings on my Facebook app multiple times and re-authenticating, it is still throwing the same error.
Using FB user to login on parse. Error code: 251, Invalid Sesion Error
Parse Facebook login fails with error code 251
For the record, I've tried changing my "App Secret embedded in the client" Facebook setting to false, as well as my "Native or desktop app?" to both yes and no (I'm fairly sure it should be set to yes, as I'm using the desktop app FB login flow.) I've also added my facebook app to my parse app, and enabled Facebook integration on parse, as well as double checking my parse app and rest api keys.
Please let me know what else I should try, or what other information you need to assess this.
Two things were wrong with the way I was approaching this.
I was creating the "Expires_at" field by adding the "Expires_in" field (returned using this FB login flow) to the current time as calculated by my browser. In retrospect this was silly, as the expiration time is supposed to be exact, and network latency will change the calculated time by a bit.
I was using the wrong facebook ID for my request - there are two types of IDs now, and you need to use the correct one. See this link..

Commenting on Facebook Page Ratings (Reviews) via Graph API

Long time lurker first time poster...
We are working with Facebooks API's to integrate into our web application and we are able to pull a Companies Page Rating via the {open_graph_story} parameter in the {page-id}/ratings section, however we cannot find a way to comment/reply to the rating. The documentation states:
"If a person has rated your page and a story has been generated, you can follow up with the person by posting to the story's comment node." (https://developers.facebook.com/docs/graph-api/reference/v2.0/page/ratings)
however when we pull the variables we retrieve no ID to reference for a comment. This is what we receive back from our authenticated account:
"data": [
{ "created_time": "2014-07-16T05:52:50+0000", "reviewer": { "id": "100000237096397", "name": "Romey Salazar" }, "rating": 5, "review_text": "Great job guys!!!!" } ],
Does anyone know how to retrieve the id for the rating itself so we can append a comment via API? Or some other way to reply/comment to a FB Page Rating?
Thanks!
When you have some ratings/review comments on your page and if you want to post comment to individual review comments as the Page Owner, you can follow the steps below.
1) Below request returns the json object of rating and reviews.
https://graph.facebook.com/v2.9/{YOUR_PAGE_ID}/ratings?field=open_graph_story&access_token={YOUR_PAGE_ACCESS_TOKEN}
The response json will contain ID field for each and every rating/review comments.
2) Using the ID, trigger the below request to post a comment on the rating as the Page Owner. You will need Page access token with manage_pages and publish_pages privilege.
https://graph.facebook.com/v2.9/{ID_OF_THE_RATING}/comments?message=Thanks for your rating&access_token={YOUR_PAGE_ACCESS_TOKEN}
These requests can be tested using Facebook Graph API Explorer
You need to request the open_graph_story field with the ratings endpoint. This will return the open_graph_story data which includes an id. You can then post to the comments endpoint of this story.
You have to make http get request on
https://graph.facebook.com/v2.9/{PageID}/ratings?fields=open_graph_story&access_token={PageAccessToken}
to get detailed response.
Make sure the parameter is "fields" not "field"

Facebook realtime updates for page contain invalid post id

I've set up a subscription so that my app receives realtime updates for a specific page. This works as expected, and I'm receiving updates when a user posts to the page.
The update only contains the page id, so I then use the Graph API to get the details of the post. The problem is that the post id in the realtime update isn't valid and I get an error from Graph API.
If I query the page's feed, the post shows up there with a different (correct) id.
The correct id consists of <page id>_<post id>. The one in the realtime update is just the <post id> without the prefixed page id.
The data in the realtime update:
{
"object":"page",
"entry":[{
"id":"<page id>",
"time":1372177485,
"changes":[{
"field":"feed",
"value": {"item":"post", "verb":"add", "post_id":<post id>}
}]
}]
}
The Graph query:
http://graph.facebook.com/<post id>
Response:
(GraphMethodException - #100) Unsupported get request.
The Graph query is being performed using a long-lived (non-expiring) page token. I get the same response using the Graph API Explorer tool (https://developers.facebook.com/tools/explorer) and also when using a short-lived user token.
Obviously I could simply prepend the page id onto the given page id to generate a valid id, but that's not very robust, should the format change at any time. Why isn't Facebook returning valid ids? Is there something I'm doing wrong?

Facebook Graph API - "Related Post" in status update

In the Facebook UI, you can hit "#" when you update your status and get a list of pages where your status update will be added as a Related Post on the page.
Is there a way to do the same in the Graph API? Assuming all authenticated, calling me/feed with a "message" parameter like this (using .NET Facebook SDK):
var client = new FacebookClient(ACCESS_TOKEN);
var parms = new Dictionary<string, object>();
parms.Add("message", "TEST fb SDK: #whatever");
client.Post("me/feed", parms);
The status update is posted, but the page doesn't doesn't get resolved as a Related Post.
If you GET a feed entry which has a Related Post created from the UI it's shown as a status update with the "to" parameter populated with the page. If you recreate that message as a POST in the API, the Related Post gets created, but:
the Related Post shows on the Info tab of the page, not the Related Posts tab
the status update doesn't have a link to the Related Post
Any thoughts? Thanks!
Someone has posted an undocumented way of tagging users using Facebook Graph API that involves using a #[{user_id}:1:{name}] syntax, eg: #[{4}:1:{Mark Zuckerberg}]. There is an open request with Facebook for full documented support of this method.