Delete facebook comment from my site or facebook Javascript SDK - facebook

I am using facebook javascript SDK to post comment on facebook and using this code:
FB.init({
//appId: 'YOUR_APP_ID', cookie: true,
appId: '2697XXXXXXXXXX098', cookie: true,
status: true, xfbml: true
});
FB.ui({
method: 'feed',
name: 'MyComment',
link: 'http://www.facebook.com./',
picture: 'http://xyz.com/App_Shared/Images/logo.jpg',
caption: 'Comment caption',
description: 'comment description',
message: 'Join facebook.'
}, function (response) {
if (response && response.post_id) {
alert('Post was published.' + response.post_id);
} else {
alert('Post was not published.');
}
});
and now i want to delete this post by using the same type of js code.
I saved post_id in my database.
Can you provide me the code or any URL to do this.....

First of all you must give to access to you application and allow by user according to this URL
http://developers.facebook.com/docs/reference/api/permissions/
These permission you can use like this method
FB.login(function (response) {
if (response.authResponse) {
FB.api('/me', function (response) {
jQuery('#hdfUID1').val(response.id);
jQuery('#btnFBLoginTemp').click();
// FB.logout(function (response) {
// });
});
} else {
jQuery('#hdfUID1').val('');
}
}, { scope: 'email,user_photos,read_stream,publish_stream,offline_access' });
if user allow these permissions then you can delete comment from user's wall which was posted by your application by using "Anatoly Lubarsky" answer method....
FB.api(postId, 'delete', function(response) {
// callback here
});

should be very simple like:
FB.api(postId, 'delete', function(response) {
// callback here
});
hope this helps

Related

How to post on a facebook test page?

I'm trying to post on a test Facebook page, but it wouldn't work here's what I did:
window.FB.api(
'/https://graph.facebook.com/700757323715208/feed',
'POST',
{message:"Hello Fans", access_token:"{access_token}"
},
function(response) {
console.log(response) }
);
and it's rendering this:
{id: "2568244933261615", url: "https://graph.facebook.com/700757323715208/feed"}
But it's supposed to render something like this :
{
"id":"1116692661689527",
"post_id":"546349135390552_1116692711689522"
}
Correct version:
window.FB.api(
'/me/feed',
'POST',
{message:"Hello Fans", access_token:"{access_token}"
}, function(response) {
console.log(response);
});
You do not need the Page ID, you have to use a Page Token of that Page anyway.

facebook js sdk post to wall

i am struggling to ad the post to wall functionality to an existing piece of code ?
It works fine with logging in and obtaing email for form submit, i would like it to post to wall on log in as well ! in the simplist way possible .?
URL to see it in action is http://lproctor.co.uk/.
// The facebook JavaScript SDK to log in to FB
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $facebook->getAppID() ?>',
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
FB.ui(
{
method: 'feed',
name: 'The Facebook SDK for Javascript',
caption: 'Bringing Facebook to the desktop and mobile web',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
link: 'https://developers.facebook.com/docs/reference/javascript/',
picture: 'http://www.fbrell.com/public/f8.jpg'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
NOW USING
<script type="text/javascript">
// The facebook JavaScript SDK to log in to FB
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $facebook->getAppID() ?>',
cookie: true,
xfbml: true,
oauth: true
});
FB.ui(
{
method: 'feed',
name: 'Facebook name',
link: 'http://lproctor.co.uk/',
picture: 'http://lproctor.co.uk/logo.jpg',
caption: 'facebook caption',
description: ' facebook description facebook description facebook description facebook description',
message: 'Facebook message!'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
Try something like that
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// connected
} else if (response.status === 'not_authorized') {
// not_authorized
login();
} else {
// not_logged_in
login();
}
});
};

Publishing on users time line using facebook javascript sdk

I have been using Graph API along with javascript facebook sdk to make posts on users wall. The code looks like this
function graphStreamPublish(){
showLoader(true);
FB.api('/me/feed', 'post',
{
message : "Sample Message",
link : 'link url',
picture : 'image url',
name : 'app name',
description : 'Test stuff'
},
function(response) {
showLoader(false);
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
Can this piece of code be used to post on users timeline as well or is there something else I need to do?
The following code works. ( Notice the 'publish_actions' permission used at the end).
FB.login(function(response) {
// handle the response
if (response.status === 'connected') {// Logged into your app and Facebook.
FB.api('/me/feed', 'post',
{
message : "Sample Message",
name : 'app name',
description : 'Test stuff'
},
function(response) {
if (!response || response.error) {
alert(response.error);
} else {
alert('Post ID: ' + response.id);
}
});
}
}, {scope: 'public_profile,email,publish_actions'} );
Years ago, you could use field TO with user id, nowadays you cant post to users timeline, but you can use TO field with an ID, for posting on groups, events or pages .

Call function after oauth success

How can I call a function, when Facebook has been authourized??
FB.ui({
client_id: '9999999999999',
method: 'oauth',
scope: 'email, user_about_me, user_likes',
response_type: 'token'
});
???
FB.Ui has a callback function.
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
Facebook state that you should not use the OAuth Dialog directly from the Javascript SDK so here's an example using FB.Login with a callback for when the user has accepted/denied the permissions.
FB.login(function(response)
{
if (response.authResponse)
{
// user has granted permissions
}
else
{
// user did not grant permissions
}
},
{
scope: 'email, user_about_me, user_likes'
}
);

FaceBook FB.ui logout dont fire

FB.ui(
{
method: 'feed',
name: 'some text',
link: 'some text',
picture: 'aa.jpg',
caption: 'some text',
description: 'some text',
message: 'some text'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
});
}
That code WORK fine, now i like after :
alert('Post was published.');
to be logged out from facebook, silently
HOW ?
Adding that code After the alert('post publish') did not do anything !!
FB.ui(
{ method:'auth.logout', display:'hidden' },
function() { alert("you're logged out!"); }
);
i have found : FB auth.logout is being raised after being logged in using the "server-side-workflow" (OAuth 2.0) but not sure i understand the code enough to know it do what i ask !
https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
https://developers.facebook.com/docs/reference/javascript/FB.logout/
Best Practices
FB.logout will log the user out of both your site and Facebook. You
will need to have a valid access token for the user in order to call
the function.
Calling FB.logout will also invalidate the access token that you have
for the user, unless you have the offline_access permission.
I wrote a sample using the comments box to fire the auto logout
http://shawnsspace.com/fb.logout.test.php
THE CODE:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '112104298812138',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
//channelUrl : 'http://WWW.MYDOMAIN.COM/channel.html', // channel.html file
oauth : true // enable OAuth 2.0
});
FB.Canvas.EarlyFlush.addResource("http://shawnsspace.com/index.php");
FB.Canvas.setAutoResize();
FB.getLoginStatus(function(response) {
if (response.authResponse) {
var accessToken = response.authResponse.accessToken;
} else {
}
});
FB.Event.subscribe('comment.create', function(response) {
//alert(JSON.stringify(response));
FB.logout(function(response) {
window.location.reload();
});
});
FB.Event.subscribe('auth.login', function(response) {
//top.location.href = 'http://apps.facebook.com/shawnsspace/fbcomments.php?ref=loggedin';
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
//top.location.href = "http://apps.facebook.com/shawnsspace/fbcomments.php?ref=loggedout";
alert('logged out');
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>