Posting an embedded video link using the Facebook Graph API - facebook

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

Related

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"

To update the cover in the face appears on the wall changed the picture, can I hide or delete this post with api?

to update the cover in the face appears on the wall changed the picture,
can i hide or delete this post with api ?.
$json_object = $facebook->api($fanpage."/? fields=cover&access_token=".$fanpage_token, 'get');
echo $page_settings_url.'<pre>';
print_r ($json_object);
$json_object = $facebook->api($fanpage.'/'.$json_object['cover']['cover_id'],'delete');
echo 'borrado'.$json_object;*/
//echo $json_object['stdClass']['cover'];
//$response = file_get_contents($page_settings_url);
//$resp_obj = json_decode($response,true);
If my interpretation of your question is correct, you want to upload a page cover photo without a story appearing on the page's timeline?
This is covered in the Page API documentation - see the Setting a Cover Photo section
You can also add a no_feed_story parameter to the upload to suppress the news feed story.
So the code for uploading the cover photo would become:
$json_object = $facebook->api($fanpage."/? fields=cover&access_token=".$fanpage_token, 'POST', array('no_feed_story' => 1));

How to refresh Facebook Like Image (clear cache) [duplicate]

We used the link:
http://www.facebook.com/sharer.php?u=[shared URL]
...to share a particular page. However, Facebook Sharer uses the cached version of the images and the title. Is there a way to quickly clear the Facebook cache or how long do we have to wait until the data gets updated?
I placed <link rel='image_src' href='[preview image]' /> in between the tags.
I found a solution to my problem. You could go to this site:
https://developers.facebook.com/tools/debug
...then put in the URL of the page you want to share, and click "debug". It will automatically extract all the info on your meta tags and also clear the cache.
Use api Is there an API to force Facebook to scrape a page again?
$furl = 'https://graph.facebook.com';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $furl );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POST, true );
$params = array(
'id' => '<update_url>',
'scrape' => true );
$data = http_build_query( $params );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
curl_exec( $ch );
$httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
Facebook treats each url as unique and caches the page based on that url, so if you want to share the latest url the simplest solution is to add a query string with the url being shared. In simple words just add ?v=1 at the end of the url. Any number can be used in place of 1.
Hat tip: Umair Jabbar
I thing these two links have a wide discussion on your problem related stuff. fb:ref clear cashes by calling
fbml.refreshRefUrl
like this
<tt>fbml.refreshRefUrl("http://www.mysite.com/someurl.php")
You can study the related stuff from here fb:ref. I hope it will work for you
The page to do this is at https://developers.facebook.com/tools/debug/ and has changed slightly since some of the other answers.
Paste your URL in there and hit "Debug". Then hit the "Fetch new scrape information" button under the URL text field and you should be all set. It'll pull the fresh meta tags from your page, but they'll still cache so keep in mind you'll need to do this whenever you change them. This is really critical if you are playing with the meta tags to get FB Shared URLs to format the way you want them to inside of facebook.
This answer is intended for developers.
Clearing the cache means that new shares of this webpage will show the new content which is provided in the OG tags. But only if the URL that you are working on has less than 50 interactions (likes + shares). It will also not affect old links to this webpage which have already been posted on Facebook. Only when sharing the URL on Facebook again will the way that Facebook shows the link be updated.
catandmouse's answer is correct but you can also make Facebook clear the OG (OpenGraph) cache by sending a post request to graph.facebook.com (works for both http and https as of the writing of this answer). You do not need an access token.
A post request to graph.facebook.com may look as follows:
POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: graph.facebook.com
Content-Length: 63
Accept-Encoding: gzip
User-Agent: Mojolicious (Perl)
id=<url_encoded_url>&scrape=true
In Perl, you can use the following code where the library Mojo::UserAgent is used to send and receive HTTP requests:
sub _clear_og_cache_on_facebook {
my $fburl = "http://graph.facebook.com";
my $ua = Mojo::UserAgent->new;
my $clearurl = <the url you want Facebook to forget>;
my $post_body = {id => $clearurl, scrape => 'true'};
my $res = $ua->post($fburl => form => $post_body)->res;
my $code = $res->code;
unless ($code eq '200') {
Log->warn("Clearing cached OG data for $clearurl failed with code $code.");
}
}
}
Sending this post request through the terminal can be done with the following command:
curl -F id="<URL>" -F scrape=true graph.facebook.com
Append a ?v=random_string to the url.
If you are using this idea with Facebook share, make sure that the og:url param in the response
matches the url you are sharing. This will work with google plus too.
For Facebook, you can also force recrawl by making a post request to https://graph.facebook.com
{id: url,
scrape: true}
I just posted a simple solution that takes 5 seconds here on a related post here - Facebook debugger: Clear whole site cache
short answer... change your permalinks on a worpdress site in the permalinks settings to a custom one. I just added an underscore.
/_%postname%/
then facebook scrapes them all as new urls, new posts.
if you are using wordpress with a cache plugin, make sure you clear all your caches. Also make sure the image you are using has the recommended facebook size: 1200(w) x 630(h) or 600 x 315.
If you used managed wordpress or caching plugins, you have to CLEAR YOUR CACHE before the facebook debugger tool can fetch new info!
I've been pulling my hair out for weeks figuring out why changes I made wouldn't show up in facebook debugger for 24 hours!!!! The fix is I have to go into my wordpress dashboard, click the godaddy icon on the top, and click "flush cache." I think many managed wordpress hosters have a cache to figure out how to clear it and you'll be golden.

facebook post a youtube video to stream.publish

I'm using the facebook SDK for iOS, but I assume that doesn't matter as every facebook platform has the post option for stream.publish
I can send a regular post just fine, but when I post a YouTube video it shows up as a link rather than a YouTube video. Is there a different option other than stream.publish I should use to accomplish posting a video?
I tried video.upload and video.publish, but neither worked. What should I do? Thanks.
I'm more familiar with the C# SDK but it shouldn't be that different.
Are you specifying the post type as a link?
Ex.
args["message"] = msg_txt;
args["title"] = title;
args["type"] = "link";
args["link"] = "http://www.youtube.com/watch?v=blahblah";
args["source"] = "http://www.youtube.com/v/" + YouTubeVideoID + "?version=3&rel=0";
Can you provide a code snippet of what you are doing?

How to share Amazon authenticated URL when posting to the wall using Facebook Graph API?

I am trying to create a Facebook wall post using Facebook Graph API. The payload is:
{ :message => 'I just uploaded image',
:picture => 'http://s3.amazonaws.com/picyou-andrey-development/images/GejoFV/GejoFV.png?AWSAccessKeyId=AKIAI6ANFCV7RKOBGGBA&Signature=U0Bd2bMQ3Pai%2BAblVOimSOVcbzk%3D&Expires=1308771841',
:link => 'http://google.com',
:name => 'Test Post' }
The post is created properly but the problem in picture which does not displays at all.
When I was using public Amazon S3 URLs like http://s3.amazonaws.com/picyou-andrey-development/images/GejoFV/GejoFV.png picture was displayed correctly.
Any chance to use dynamic URLs as a 'picture' param with Facebook?
Thanks in advance.
Update:
Found a guy on the Facebook developer forum with exactly the same problem:
http://forum.developers.facebook.net/viewtopic.php?pid=302856
Could it be that the signature part of the url has some chararcters in it that have special meaning in urls - %2B (+) and %3D (=)?
I have run into a problem with these urls in some video players and solved it by making sure that the url doesn't have any of those characters. You can do this by generating the url in a loop and adding a second onto the expiry time everytime to ensure the signature changes. Repeat until the signature is 'valid'
psuedocode:
loop
expiry = expiry + 1 second
create url with expiry
until url is valid
In my experience it only takes an iteration or two for the url to be valid.