How to Publish to Timeline
Review the official instructions from Facebook first: https://developers.facebook.com/docs/opengraph/tutorial/
There are additional instructions here that helped me. http://onlytipsandtricks.com/facebook/how-to-publish-actions-on-timeline/
However, the code used in there did not work for me and failed. After many hours spent playing around with the code I have the following:
<html 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# fb: http://ogp.me/ns/fb# article: http://ogp.me/ns/article#">
<title>OG Tutorial App</title>
<meta property="fb:app_id" content="[YOUR_APP_ID]" />
<meta property="og:type" content="article" />
<meta property="og:title" content="Sample article" />
<meta property="og:image" content="http://nopenonlytext.tnguyen.com/wp-content/uploads/2012/09/maui-2012.jpg" />
<meta property="og:description" content="Sample object Publishing" />
<meta property="og:url" content="http://nopenonlytext.tnguyen.com/test.html">
<script type="text/javascript">
function postPublish()
{
FB.api(
'/me/Publish',
'post',
{ article: 'http://nopenonlytext.tnguyen.com/test.html' },
function(response) {
var msg = 'Error occured';
if (!response || response.error) {
if (response.error) {
msg += "\n\nType: "+response.error.type+"\n\nMessage: "+response.error.message;
}
alert(msg);
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
}
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '[YOUR_APP_ID]', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<h3>Sample Object</h3>
<p>
<img title="Maui"
src="http://nopenonlytext.tnguyen.com/wp-content/uploads/2012/09/maui-2012.jpg" />
</p>
<br>
<form>
<input type="button" value="Publish" onclick="postPublish()" />
</form>
</body>
</html>
You can see the complete code also here from when I created the test page.
http://nopenonlytext.tnguyen.com/test.html
I hope this helps but feel free to ask me any questions.
As I'm having issues preserving the HTML code I have in this post since switching to "Visual" from "HTML" reformats the HTML code. I have attached the HTML code for reference when I find that it's all mangled I can revert it back.
html-code-for-post
No comments:
Post a Comment