Error when creating Facebook Canvas header through API - facebook

I'm getting the error :
Param canvas_header[child_elements][0] must be a valid rich_media_photo_element id"
When using using the following (URL obscured):
curl \
-F 'canvas_header={
"name": "Test Header 20170924",
"background_color": "000000",
"child_elements": ["<photo id>"]
}' \
-F 'access_token=<token>' \
https://graph.facebook.com/v2.10/<page id>/canvas_elements
I can't work out why the error is appearing. I've added a bunch of photos and used them for cover images in canvas, but this error is appearing for the header element and also the carousel.
Any ideas?

I'm answering my own question because there's such a paucity of references on the web in general.
For carousels, headers and footers, the photos must already be imported in as cover images to get a canvas photo ID and then added to the code above as a child element.

Related

How to add 'Get Started' button in facebook messenger chat bot?

I tried using this
curl -X POST -H "Content-Type: application/json" -d '{ "get_started": {"payload": "qr"} }' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=myPageAccessToken"
In response I also got { "result": "success" }
But the bot does not show any button.
First, make sure that your account facebook who try to use your bot since only admins/developers/testers of the app can see it when the app is in development.
Second, if you use Android, you need to clear the Messenger data/cache under Android Settings -> Apps, this will also clear your login and you need to login again.
For further information, you could check this out:
https://stackoverflow.com/a/42662751/6874563
It was working fine, All I had to do was, deleting the existing conversion.
In my case, get started button only appears, when there's no message exists in past.

LinkedIn: Creating a company share for a photo

I'm suffering to create a company photo share on Linkedin.
I've seen several threads, where people say, they could create a photo share on LinkedIn by creating a link share, passing the image URL for the "submitted-url".
E.G. Consider the following payload:
```
{
"visibility": { "code": "anyone" },
"content": {
"submitted-url": "localhost/image.jpg"
}
}
```
In my case, at least, the share appears as a link share on LinkedIn. I've also tried the combinations of providing the "title" etc. fields, but no luck.
Next, I've found the following documentation: https://developer.linkedin.com/docs/guide/v2/shares/rich-media-shares#upload
That does not seem to be linked from the https://developer.linkedin.com/docs, so I have no clue if this documentation still applies.
I've tried the following endpoint: "https://api.linkedin.com/media/upload" with the "Content-Type: application/x-www-form-urlencoded" and "Authorization: Bearer ..." -headers, with file payload but the response is:
```
{
"serviceErrorCode": 100,
"message": "Not enough permissions to access media resource",
"status": 403
}
``
It does not matter, what permissions I have set for my app.
I happen to know from some applications, there is a way to share photo shares on LinkedIn via the API, but I don't manage to find the correct documentation where this is described.
If you know a way that worked for you but isn't already listed here, please inform me and all the others suffering from this problem :)
And if someone from LinkedIn could add the proper documentation, that would be superb!
Thanks!
Meanwhile, our application got accepted to LinkedIn "marketing partner" program which gives you access to LinkedIn API V2, the documentation is publicly available, but you need to manually apply for it. They may or may not accept your application.
Just couple gotchas for the next person who may struggle with this or some other issues we encountered.
Once our application got accepted to the "marketing partner"-program, we started to receive strange errors for our LinkedIn v1 API calls, namely "410 Gone" - "This resource is no longer available under v1 APIs".
All the calls using the application that got the permissions to API v2 were failing to this error. There was no way to use the old API with that application any longer.
The email confirming our application's acceptance to the program was sent to us in one day delay from when these problems started. Strange way to deal API switch, but luckily we have access to API v2 now.
LinkedIn API v2 gives you the possibility to upload and publish photo shares (one or many photos), which isn't possible with API v1.
The error we received for every call to API v1 after the acceptance:
{
"status": 410,
"message": "This resource is no longer available under v1 APIs",
"errorCode": 0,
"requestId": "removed",
"timestamp": 1522333590761
}
LinkedIn provides rich media API to do an image share.
Lets assume you already have an access token (access_token), your organization id is org_id and the image file name is "flower.png"
1) Below call helps you to upload the image to LinkedIn using upload media API
curl -X POST \
https://api.linkedin.com/media/upload \
-H 'authorization: Bearer <access_token>’ \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F fileupload=#flower.png
The above call returns the below response format:
{
"location": “<image_urn>“
}
2) Now using the above image_urn in response, you will be able to create an image share using the below call
Please replace access_token, org_id and image_urn with the original values before making the below call
curl -X POST \
https://api.linkedin.com/v2/shares \
-H 'authorization: Bearer <access_token>’ \
-H 'content-type: application/json' \
-d '{ "owner": "urn:li:company:<org_id>“,
"text": {
"text": "test image attachemnt 0614"
},
"subject": "test image attachemnt 0614",
"distribution": {
"linkedInDistributionTarget": {}
},
"content":{
"contentEntities": [
{
"entity": “<image_urn>”
}
],
"description": "content description1",
"title": "Test Share with Image"
}
}'

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..

Facebook Ads API - How to create NewsFeed ads?

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"

Posting an embedded video link using the Facebook Graph API

When manually attaching a video link (from YouTube, Vimeo, etc) to a post using the Facebook web interface, Facebook automatically recognizes the link as a video, and allows the resulting status message to play the video inline. The video is displayed as an embedded player in the Wall or News feed.
Here's an example of what an embedded video looks like after posting manually.
When posting a link using the Graph API, the video is not embedded.
curl -F 'access_token=...' \
-F 'message=Link to YouTube' \
-F 'link=http://www.youtube.com/watch?v=3aICB2mUu2k' \
https://graph.facebook.com/me/feed
I suspect the answer is related to the source argument, but I'm not sure what the URL should be there. Specifying the same URL just leads to a post with no thumbnail image whatsoever.
source: A URL to a Flash movie or video file
to be embedded within the post.
read_stream.
How can the same embedded behavior be accomplished by using the Graph API alone?
It appears that you have to extract the URLs of the actual swf in the page and the thumbnail image yourself. For example, this seems to work:
curl -F 'access_token=...' \
-F 'message=Link to YouTube' \
-F 'link=http://www.youtube.com/watch?v=3aICB2mUu2k' \
-F 'source=http://www.youtube.com/v/3aICB2mUu2k' \
-F 'picture=http://img.youtube.com/vi/3aICB2mUu2k/0.jpg' \
https://graph.facebook.com/me/feed
It appears that you can generate a valid source and picture from the page URL. The URL looks like http://www.youtube.com/watch?v=<code>; take the code (3aICB2mUu2k here) and insert it into the URLs http://www.youtube.com/e/<code> for the source and and http://img.youtube.com/vi/<code>/0.jpg for the picture.
Here's how to post a video manually for YOUTUBE and VIMEO (hard to find online). Specifically if you want to have the LINK value pointing to a user's website/blog post where it originates.
//search for youtube.com and vimeo.com in the 'link' value
if (preg_match("/youtube.com/", $model->link) || preg_match("/youtu.be/", $model->link)){
if (preg_match('%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $model->link, $match))
{
$video_code = $match[1];
}
$source = 'http://www.youtube.com/e/'.$video_code;
$picture = 'http://img.youtube.com/vi/'.$video_code.'/0.jpg';
}
else if (preg_match("/vimeo.com/", $model->link))
{
if (preg_match('/vimeo\.com\/(clip\:)?(\d+).*$/', $model->link, $match))
{
$video_code = $match[2];
}
/* Get Vimeo thumbnail */
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$video_code.php"));
$picture = $hash[0]['thumbnail_medium'];
$source = 'https://secure.vimeo.com/moogaloop.swf?clip_id='.$video_code.'&autoplay=1';
}
$args = array(
'message' => //user's comment
'name' => //Title of post
'link' => 'http://...'//link to video on user's website
'source' => $source,
'picture' => $picture,
);
if ($this->_facebook->api("/".$this->facebookUserID."/feed", "post", $args)){
//posted to facebook
}
Sharing as a link with /links instead of /feed seems to work better. YouTube, Vimeo, and Facebook videos are embedded as if posting manually.
curl -F 'access_token=...' \
-F 'message=Link to YouTube' \
-F 'link=http://www.youtube.com/watch?v=3aICB2mUu2k' \
https://graph.facebook.com/me/links
Don't use /feed, use /links (https://graph.facebook.com/me/links/ ) and simply POST "message" and "link" parameters using the YouTube /watch?v=ZL7nV7WwJKg URL format. /feed never worked for me, it just posted a static graphic and link but I wanted it to actually play embedded on Facebook as it does when you share the Video from YouTube to Facebook. Works like a charm.
It will not work for posting in GROUPS on /feeds or /links.
See here. Please upvote the issue in order to be fixed sometime soon.
/links is a duplicate of the /feeds which
only shows posts of type link posted by the user themselves.
Instead try posting the link as the message attribute, it works for me that way.
message = your message + link
Sharing using the API any .swf file or video wont show a thumbnail on facebook unless its youtube . And that is by design as per facebook.
Check this link
https://developers.facebook.com/bugs/589975484398226?browse=external_tasks_search_results_526fc388b99e18881434478