How to post to an Authorised User (with extended permissions) wall - Facebook JS SDK + Graph API
I know this question has been asked a thousand time, but I have yet to come across a definitive answer开发者_开发百科.
How does an application (external website, so no fbml) post to a users wall, using JS and Graph API?
I have established extended permissions with users, and can post to walls using Facebooks sample code, however the variables within the script wont appear on FB.
For Example:
function publish_test(){
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { body: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response);
}
});
}
This posts to the users wall, however it does not contain the body. Any help on this would be gratefully appreciated.
FB.ui will pop up a confirmation dialog to the user, not sure if you want that or not. http://developers.facebook.com/docs/reference/javascript/FB.ui
This page has documentation about the FB.api call: http://developers.facebook.com/docs/api Scroll down to the "Publishing" section and notice that there's no "body" parameter specified. There is a "message" parameter though. The other example you're looking at is probably incorrect?
I got this code working
function graphStreamPublish(){
var body = document.getElementById("txtTextToPublish").value;
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
精彩评论