Post Current URL Link Using Facebook SDK - facebook

I am trying to create a script that authenticates facebook users and posts on their wall every post they open from my site.
I have already built the authentication part. However, on the part when it automaticly posts on a user's wall, I can't get it to post the URL of the post that they are reading but only a static URL
This is My Watch.php
<?
include"func/ob_get_clean.php";
require 'config.php';
require_once 'inc/lib/facebook.php';
require_once 'inc/fb.php';
$string = get_include_contents('func/db_info.php');
include("admin/settings".".php");
$surl = $_SERVER['HTTP_HOST'] ;
$getid=$_GET['v'];
if(is_numeric($getid)){
mysql_query("UPDATE videos SET views=views+1 WHERE id='$getid'");
} else {
include"func/404.php";
}
$vi=mysql_query("SELECT * FROM videos WHERE id='$getid' LIMIT 1");
$v = mysql_fetch_object($vi);
$vidID = "$v->videoid";
$url = "http://gdata.youtube.com/feeds/api/videos/". $vidID;
$doc = new DOMDocument;
$doc->load($url);
$title = $doc->getElementsByTagName("title")->item(0)->nodeValue;
$des = $doc->getElementsByTagName("description")->item(0)->nodeValue;
$key = $doc->getElementsByTagName("keywords")->item(0)->nodeValue;
//$token is the access token from the URL above
$post = array('access_token' => $token,
'link' => 'www.mywebsitelink.com');
try{
$res = $facebook->api('/me/feed','POST',$post);
print_r($res);
} catch (Exception $e){
echo $e->getMessage();
}
?>
<head>
<html xmlns:fb="http://ogp.me/ns/fb#">
<title><?=$title?></title>
<meta property="og:url" content="http://<?=$surl?>/watch.php?v=<?=$getid?>"/>
<meta property="fb:app_id" content="<?=$fbappid?>"/>
<meta property="og:title" content="<?=$title?>"/>
<meta property="og:type" content="video" />
<meta property="og:image" content="http://img.youtube.com/vi/<?=$v->videoid?>/hqdefault.jpg"/>
<meta property="og:description" content="<?=$des?>"/>
<meta property="og:site_name" content="YourVidz"/>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8">
<META NAME="ROBOTS" CONTENT="INDEX">
<META NAME="AUTHOR" CONTENT="Menti">
<META HTTP-EQUIV="CONTENT-LANGUAGE" CONTENT="en-US">
<META NAME="COPYRIGHT" CONTENT="© 2011 Galeria Shqip">
<META NAME="title" CONTENT="<?=$title?>">
<META NAME="DESCRIPTION" CONTENT="<?=$des?>">
<META NAME="KEYWORDS" CONTENT="<?=$key?>">
<link href="img/favicon.ico" rel="icon" type="image/x-icon" />
<link type="text/css" rel="stylesheet" href="css/watch.css" />
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
</head>
<body>
<div class="banner"><?=$banner?></script></div>
<img src="img/logo.png" border="0">
<div align="center"><h3><?=$title?></h3><br>
<iframe src="vid.php?v=<?=$getid?>" height="378px" width="562px" frameborder="0" scrolling="no"></iframe><br>
<table border="0" cellpadding="3" cellspace="0" width="562px"><tr>
<td width="400px"><?=$v->views?> Views</td>
<td>
<div class="addthis_toolbox addthis_default_style addthis_16x16_style">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_6"></a>
<a class="addthis_button_google"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
</td></tr></table>
<br>
<fb:comments href="http://<?=$surl?>/watch.php?v=<?=$getid?>" num_posts="5" width="562" data-colorscheme="dark"></fb:comments>
</div>
<div style="display:none">
<?=$online?>
</div>
</body>

Related

Facebook share inside facebook showing og:title & og:image of the iframe

I am placing an iFrame (xx.com) at the client website (yy.com), the iFrame has a facebook share that should redirect to the client site (yy.com). The problem is with the og:image & og:title as I am placing them in xx.com bcz I have no access to yy.com. The share is not displaying the image and title I am placing in xx.com. Is there a way to do so?
the code in xx as follows:
<head>
<meta property="og:url" content="yy.com" />
<meta property="og:title" content="title" />
<meta property="og:image" content="image-path" />
</head>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/ar_AR/all.js#xfbml=1&appId=xxapp-id";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-share-button" data-href="yy.com" data-type="button_count"></div>
The code in yy.com is as follows:
<iframe width="950" height="600" frameborder="0" src="http://xx.com/path-to-file"></iframe>
I found a workaround for this as follows:
I redirect the share button to xx.com instead of yy.com having the title and the image url as a parameters in the URL and then inside xx.com I set the og:title and og:image according to the parameters passed and I redirect the user to yy.com
The share button in xx is as follows:
<div class="fb-share-button" data-href="xx.com?share_url=yy.com&title=the_title&image=the_image" data-type="button_count"></div>
The code for redirecting in xx is as follows:
<?php
$share_url = $_REQUEST['share_url'];
if(isset($share_url) && $share_url!=''){
$video_title = $_REQUEST['title'];
$video_image = $_REQUEST['image'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="<?php echo $video_title ?>" />
<meta property="og:image" content="<?php echo $video_image ?>" />
<meta http-equiv="refresh" content="0; url=<?php echo $share_url ?>" />
</head>
<body>
</body>
</html>
<?php
}
?>

like button publish: name user liked index of/ on app name

i have a problem with like button: if clicked, it shows on timeline this post:
{name user} liked index of/ on {app name} with correct description and thumbnail
i put these metatag
<meta name="description" content="Ho appena creato la mia storia con ''Lettere d'amore'' di Goldenpoint. Fallo anche tu e avrai subito un buono sconto del 10% da utilizzare in tutti i negozi goldenpoint e sullo shop on line" />
<meta property="og:image" content="<?php echo $urlThumb; ?>" />
<meta property="og:title" content="Goldenpoint Lettere d'amore" />
<meta property="og:type" content="game" />
<meta property="og:url" content="<?php echo "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";?>" />
<meta property="og:site_name" content="Goldenpoint Lettere d'amore" />
<meta property="fb:admins" content="xxxxxxxxxxxxxx" />
and like button is:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/it_IT/all.js#xfbml=1&appId=404791622949241";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="http://apps.facebook.com/lettereamore/" data- send="false" data-layout="button_count" data-width="450" data-show-faces="true"></div>
with debugger i see a weird thing: if i type the website url, everything is perfect, but if i do a test by using the url of the facebook app, it returns index of
how i can fix this?
thank you

Created Facebook Application Not Working

I have tried to follow the sample tutorial of facebook : developers.facebook.com/docs/opengraph/tutorial/#debug
But after i made it and clicked on cook button , it is showing "Error Occured".
You can see the app here : http://www.akashbc.com/facebookapp/index.html
The following is the page source for the app:
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head prefix="og: http://ogp.me/ns# og_recipebox: http://ogp.me/ns/apps/abcrecipelist#">
<meta property="fb:app_id" content="258611890922127" />
<meta property="og:type" content="abcrecipelist:recipe" />
<meta property="og:title" content="Oreo Stuffed Cookies" />
<meta property="og:image" content="http://1.bp.blogspot.com/-92sA7pC51pg/T9CKdHHeDzI/AAAAAAAACbg/MRq4PR2P5QQ/s1600/jQuery_Cookies.jpg" />
<meta property="og:description" content="The Turducken of Cookies" />
<meta property="og:url" content="http://www.akashbc.com/facebookapp/index.html">
<script type="text/javascript">
function postCook()
{
FB.api('/me/abcrecipelist:cook&recipe=http://www.akashbc.com/facebookapp/index.html','post', function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post was successful! Action ID: ' + response.id);
}
});
}
</script>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'258611890922127', cookie:true,
status:true, xfbml:true, oauth:true
});
</script>
<fb:add-to-timeline></fb:add-to-timeline>>
<h3>
<font size="30" face="verdana" color="grey">Stuffed Cookies
</font>
</h3>
<p>
<img title="Oreo Stuffed Cookies" src="http://1.bp.blogspot.com/-92sA7pC51pg/T9CKdHHeDzI/AAAAAAAACbg/MRq4PR2P5QQ/s1600/jQuery_Cookies.jpg" width="550"/><br />
</p>
<form>
<input type="button" value="Cook" onclick="postCook()" />
</form>
<fb:activity actions="YOUR_NAMESPACE:cook"></fb:activity>
</body>
</html>
Also here is the screenshot from basic settings of the app :
Please tell me whats wrong..
Thanks in advance :)
Your API call is incorrect:
FB.api('/me/abcrecipelist:cook&recipe=http://www.akashbc.com/facebookapp/index.html' ...
Should be
FB.api('/me/abcrecipelist:cook?recipe=http://www.akashbc.com/facebookapp/index.html' ...
I.e. The & should be a ?.

How come the publish_action is so unstable?

Below you can find the code I use, as you can see it has been copied from the sample code. However the result is very unstable, more than often it returns 'unexpected error please try again later', also the dev app has some problems. At random it clears the app namespace, while I did not delete it. In fact, the app namespace is still active so if I re-enter my app namespace it says it already exists.
This has kept me busy for 12 hours now. I was wondering if other people are experiencing the same problem that it might be a bug on the Facebook part.
<html xmlns:fb="http://ogp.me/ns/fb#"
xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head prefix="og: http://ogp.me/ns# mycookieapp:
http://ogp.me/ns/apps/mycookieapp#">
<title>OG Tutorial App</title>
<meta property="fb:app_id" content="115973895205576" />
<meta property="og:type" content="mycookieapp:recipe" />
<meta property="og:title" content="Stuffed Cookies" />
<meta property="og:image" content="http://fbwerks.com:8000/zhen/cookie.jpg" />
<meta property="og:description" content="The Turducken of Cookies" />
<meta property="og:url" content="http://www.crystalminds.nl/facebook/index.html">
<script type="text/javascript">
function postCook()
{
FB.api(
'/me/mycookieapp:cook?recipe=http://www.crystalminds.nl/facebook/index.html',
'post',
function(response) {
if (!response || response.error) {
alert('Error occured: ' + response.error.message);
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
}
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '115973895205576', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/nl_NL/all.js#xfbml=1&appId=115973895205576";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<h3>Stuffed Cookiess</h3>
<p>
<img title="Stuffed Cookies"
src="http://fbwerks.com:8000/zhen/cookie.jpg"
width="550"/>
</p>
<br>
<form>
<input type="button" value="Cook" onclick="postCook()" />
</form>
</body>
</html>

Not able share a video link created by the Open graph protocol in the facebook

I have create a video link using Open Graph protocol. After clicking on like button that link comes on my wall post. Now I am going to share it but it's not sharing.
My code for generate video link something like this
`
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<title>Facebook Like Demo</title>
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# video: http://ogp.me/ns/video#">
<meta property="fb:app_id" content="xxxxxxxxxxx" />
<meta property="og:title" content="title.." />
<meta property="og:description" content=" some description..." />
<meta property="og:type" content="video" />
<meta property="og:image" content="image url" />
<meta property="og:video" content="video url" />
<meta property="og:video:type" content="application/x-shockwave-flash" />
<meta property="og:video:width" content="400" />
<meta property="og:video:height" content="300" />
<meta property="og:site_name" content="test_app" />
</head>
<body>
<div id="fb-root">
</div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=xxxxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<fb:like href="link url" send="true" width="450"
show_faces="true">
</fb:like>
</body>
</html>
`
I have a feeling that the URL is not being seen correctly by Facebook's servers when they call out to it. Run your URL thru the linter tool and fix any warnings and errors it tells you about. The linter is: https://developers.facebook.com/tools/lint