Post On facebook using javascript SDK
below id the code to create comment box on you page to post the comment on facebook page just you need to put your page facebook pageid/appid where you want to post the comment.
<
script
type="syntaxhighlighter" class="brush: csharp">
<![CDATA[
{
window.fbAsyncInit = function() {
FB.init({
// window.location.reload();console.log(response); FB.getLoginStatus(function(response) { appId: ' YOUR APP ID ',
xfbml: true,
status: true,
cookie: true,
oauth: true,
channelUrl : 'CHANNEL URL / REDIRACT URL', // Channel File
});
FB.Event.subscribe("auth.authResponseChange", function(response) {
});
if (response && response.status == 'connected') {
FB.api('/me', function(response) {
});
} else if (response.status === 'not_authorized') {
} else {
}
});
};
(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";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
FB.login(
function(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
console.log("token:==>");
console.log(access_token);
FB.api(
'me/photos',
'post', {
name:"My Post",
message: 'here is yor post message',
status: 'success',
access_token: access_token,
url:$("#myimage").attr("src"); /// yourimage url is here
},
function(response) {
if (!response || response.error) {
console.log(response);
alert('Error occured:' + response);
} else {
// document.getElementById('imguploadheader').innerHTML="Status";
alert(Sucessfully posted);
}
});
} else {
errordisplay();
$("#appendtext").html(
"User cancelled login or did not fully authorize.");
$("#uploadingpregress")
.css("display","none");
successfullyupload();
}
}, {
scope: 'user_photos,photo_upload,publish_stream,offline_access'
});
}
]]>
</
script
>
No comments:
Post a Comment