Post a facebook page/feed with image using graph api - facebook

I'm struggling to post a facebook page/feed with a image.
I'm following all the documentation but, damm :(, it's not working
https://developers.facebook.com/docs/graph-api/reference/v2.10/page/feed#publish
using the object_attachment to pass and upload photo id.
I've tried with an already uploaded image and a new upload but
Nothing appears to work
If i run this, all works as expected but the image does not work
$args = array( 'access_token' => $pag_access_token,
'message' => $description,
'object_attachment' => $photoID,
'link' => $link);
$status = $facebook->api("/$facebookUsername/feed", 'post', $args);
Note: $photoID is a valid facebook photo.
Result:
Any thoughts??
Update: SOLUTION
Thanks to #Norbert insights heres how we can accomplish that:
Using the Graph api we need to pass the access_token, the link (important) and a description (optional)
On the api endpoint, i was just sharing the message and the link to my frontend page.
$args = array( 'access_token' => $pag_access_token,
'message' => "option text",
'link' => $options['link']);
$status = $facebook->api("/$facebookpage/feed", 'post', $args);
With the above code you will be able to share to facebook feed your message, but without the title of your post and the image.
To do that you will need to add the following metadata into your destination page ($link that was shared)
2.
<meta property="og:url" content="YOUR URL">
<meta property="og:type" content="website">
<meta property="og:title" content="URL TITLE">
<meta property="og:description" content="SMALL DESCRIPTION">
<meta property="og:image" content="http://IMAGE SERVED WITH HTTP">
<meta property="og:image:secure_url" content="https://IMAGE SERVED AS HTTPD">
if the url you want to share is served over https you must also include the og:image:secure_url
They need to be served under the same protocol.
Hope this help everyone with the same problem.
Regards

Related

Facebook Send method fetching wrong content?

I am using facebook send method for invite friends in my website.
this is the code
function FacebookInviteFriends()
{
FB.ui({
method: 'send',
name: 'Join Stuffuneed',
picture: '<?php echo $this->getSkinUrl('images/owl_logo_250_250.jpg') ?>',
link: '<?php echo $customerLink?>',
description: "You have been invited to join Stuffuneed. Stuffuneed is the place to find the stuff you always needed but didn't know where to find",
});
}
it's showing me this dialog
problem is this
it's not showing me exact name.picture,link description.
i have also use og meta tags
<meta property="og:title" content="Join Stuffuneed" />
<meta property="og:image" content="http://www.stuffuneed.com/stuffuneed/skin/frontend/default/lockrez/images/owl_logo_25_250.jpg"/>
<meta property="og:site_name" content="Stuffuneed"/>
<meta property="og:url" content="http://www.stuffuneed.com/stuffuneed/"/>
<meta property="og:type" content="website"/>
but it's still showing me wrong content
Pls help me...
description picture are not the valid parameters in the send dialog. Reference
You'll just have to provide the link; and fb will fetch the image by itself. May be you can set the meta tag of og:image in the link you have provided.

Featured image doesn't show when link is shared in Facebook

Hello Dear Stack Overflow friends! I've been trying to solve this problem for a couple of days with no success. I've read almost every post available here at Stack Overflow but I can't find out how to solve this.
When I share a link on Facebook, the thumbnail corresponds to the image I defined in the
meta property="og:image"
It works and everything is fine there... But,
I would like that each post could display its own featured image as a thumbnail when shared. How on earth can I do that?
I've tried with this code in function.php
function insert_image_src_rel_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
return;
if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
$default_image="http://example.com/image.jpg"; //replace this with a default image on your server or an image in your media library
echo '<meta property="og:image" content="' . $default_image . '"/>';
}
else{
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
}
echo "
";
} add_action( 'wp_head', 'insert_image_src_rel_in_head', 5 );
And nothing happens...
I've also tried this code in header.php
<?php
global $wp_query;
$thePostID = $wp_query->post->ID;
if( has_post_thumbnail( $thePostID )){
$thumb_id = get_post_thumbnail_id( $thePostID );
$image = wp_get_attachment_image_src( $thumb_id );
echo '<meta property="og:image" content="'.$image[0].'" />';
} ?>
No success there either.
The featured image is activated in the functions.php like this.
add_theme_support('post-thumbnails');
As I said, all og tags are set.
What Is happening? It's not a cache thing because I'm using the facebook debugger to flush it.
I will be eternally grateful if anybody out there can help me.
Thanks a lot.
Benjamin.
I think you should try like
echo '<meta property=\"og:image\" content=\"'.$image[0].'\" />';
also, pls check your source code after updating this if <meta property is displaying correct when site is rendered
Ok I fixed this... Maybe this will help other users with the same problem... The reason it was using the same thumbnail in every link despite rendering the correct image in the source code is because of the
<meta property="og:url" content=" line.
I entered there the URL of the site and of course, the canonical URL ruled them all, and the debugger went there to fetch the featured image. I replaced that value with
<?php echo get_permalink(); ?>
And that did it. Thank you for your kind help I hope this question helps others solve similar issues.
You can use meta property like this.
<meta property="fb:app_id" content="facebook app id" />
<meta property="og:url" content="post url">
<meta property="og:title" content="post title">
<meta property="og:description" content="post description">
<meta property="og:image" content="image url"/>

posting a swf in facebook feed through facebook api

I am using the below array and
$feeddata = array(
'type'=>'flash',
'method'=>'stream.publish',
'display'=>'iframe',
'link'=> 'https://developers.facebook.com/docs/reference/dialogs/',
'source'=>'http://www.hackerdude.com/channels-test/swfscout_VideoSample.swf',
'picture'=> 'http://fbrell.com/f8.jpg',
'name'=> 'Facebook Dialogs',
'caption'=> 'Reference Documentation',
'description'=> 'Using Dialogs to interact with users.');
and passing it to facebook->api($userid.'/feed', 'POST', $feeddata );
But in the feed i can see only the image and when i click in the image it takes me to the link, how can i see swf in the feed (ideally on clicking on the picture it should toggle to swf)
The type should be "video" instead of "flash". Here's a parameter array that produced a playable video in my tests:
array(
'type'=>'video',
'source'=>'http://www.hackerdude.com/channels-test/swfscout_VideoSample.swf',
'picture'=> 'http://fbrell.com/f8.jpg',
'name'=> 'Facebook Dialogs',
'caption'=> 'Reference Documentation',
'description'=> 'Using Dialogs to interact with users.',
);
Note that there's no link attribute, that's because as it seems to me, the facebook API has a bug at this moment where if you provide a link then it won't embed your video.
The bug theory reinforced by that the JS SDK does indeed accept a link and produce a playable video, you could migrate to this method for publishing if its feasable, with parameters like this:
FB.ui({
method:'feed',
type: 'video',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
source: 'http://www.hackerdude.com/channels-test/swfscout_VideoSample.swf',
description: 'Using Dialogs to interact with users.'
});
Workaround
The embedding seem to be working fine if you post a link that has the proper opengraph meta tags for video embedding, here's an example:
the link to be shared (video brought to you by youtube)
<html>
<head>
<title>Fly, you fools!</title>
<meta property="og:title" content="Fly, you fools!" />
<meta property="og:type" content="website"/>
<meta property="og:description" content="Content for Description" />
<meta property="og:image" content="http://i2.ytimg.com/vi/meOCdyS7ORE/mqdefault.jpg" />
<meta property="og:site_name" content="Content for caption"/>
<meta property="og:video" content="http://www.youtube.com/v/meOCdyS7ORE?version=3&autohide=1">
<meta property="og:video:type" content="application/x-shockwave-flash">
<meta property="og:video:width" content="640">
<meta property="og:video:height" content="360">
</head>
<body>
<script>
window.location = 'http://disney.com'; // redirecting users who's clicking on the link, wont affect crawlers since its in js.
</script>
</body>
</html>
php sdk call to share it
$this->facebook->api('/me/feed', 'post', array(
'type' => 'link',
'link' => 'http://.../', // put the html file's location here
));
write one more met tag :
<meta property="og:video:secure_url" content="https://...game url.">
"
try to put "https:// " game url ,i.e game swf url with ssl, because fb takes only ssl url to play videos or swf file for game.
Hope this will be useful.

video post on timeline not playing inline

I have a problem when posting video through my app on users with TimeLine profile.
the post appears very small and when clicked the video opens on a new tab instead of playing inside facebook.
Here are some details :
I'm building an application that create customized videos (SWF) and post them on a user's friend wall.
I'm "wrapping" the SWF file in an HTML file that include the following "meta og:" tags -
<meta property="fb:app_id" content="******" />
<meta property="og:url" content="THIS PAGE URL" />
<meta property="og:title" content="Title" />
<meta property="og:description" content="some description" />
<meta property="og:type" content="video" />
<meta property="og:image" content="an img url" />
<meta property="og:video" content="URL TO THE SWF FILE" />
<meta property="og:video:type" content="application/x-shockwave-flash" />
<meta property="og:video:width" content="396" />
<meta property="og:video:height" content="297" />
<meta property="og:site_name" content="pickle-games" />
and then in the body i embed the SWF using the "embed" tag.
You can see an example by viewing the source of http://pickle-games.com/BigBully/hitVideo.php?hit_id=1327242593&hit=hit2
I'm using the facebook PHP SDK to post on the wall like this :
$facebook->api("/" . $uid . "/feed", "POST",
array(
'link' => $server_url . 'hitVideo.php?hit='. $hit . "&hit_id=".$hit_id ."&u_name=" . $u_name . "&f_name=". $f_name
));
When posting on a user with the old profile (not the timeline) everything works fine and the video plays inline, on the wall.
The problem, as mentioned above, is only when posting on a user that uses the TimeLine profile
BTW - if i share the link manually (not through my app) on the friend's timeline then everything works fine...
What am i missing?
How do i post it through my app in a way that it will work also on the timeline?
Thanks.
Try this
$attachment = array(
'message' => 'SOMETHING HERE!',
'name' => 'name!',
'caption' => 'caption!',
'link' => 'http://link.com',
'description' => 'description here!',
'access_token' => $request["oauth_token"],
'picture' => 'http://link.com/image.jpg',
'source' => 'link.com/flash.swf',
'actions' => array(array('name' => 'some action',
'link' => 'https://link.com/'))
);
$result = $facebook->api('/'.$friend_id.'/feed/','post',$attachment);
It is very important to put something in the 'message' or else is going to give you that same error...
Just a note, if you do not have
<meta property="fb:app_id" content="xxxxxxxxxxxxxxxx" />
When posted to the wall, the video will open in a NEW window.

wrong og:description

Facebook does not get information from description Open Graph tags
I do get following error but not for description field
The og:url property should be explicitly provided, even if a value can
be inferred from other tags.
I do have in header (Wordpress)
<meta property="og:description" content="<?php echo strip_tags(the_excerpt()); ?>" />
bugzilla shows correct source of the page
<meta property="og:description" content="<p>3D organs modeled for real-time DVD application</p>" />
But on fb page description shown is
JavaScript code from google analytics :)
"var _gaq = _gaq || []; _gaq.push(['_setAccount'..."
Do you spot the error somewhere?
By the way... I know fb caches information... is there a way to reset it?
To refresh the cache run the url through Facebooks URL Linter here http://developers.facebook.com/tools/debug. What is the url you are trying to parse?