adding Facebook friends to a friendlist with FB.api - javascript

How can I add friend(s) to a friendlist using JavaScript SDK?
I found this example for using POST method in order to post the message to the feed:
var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
However, I do not understand, how it works. Ehat is 'message' in { message: body } and how it can be adapted to this matrix "/FRIENDLIST_ID/members?members=1,2,3" (this is from FB.api examples ar https://developers.facebook.com/docs/reference/javascript/FB.api/

This is what worked for me. Make sure the key is enclosed within quotes. 'members' in this case. Though I was able to create lists, trying to add members to a created list kept throwing an exception with a message saying 'Manage_friendlists permission required' thought I had that permission. Turns out one needs the publish stream permission as well in order for this to work. This wasn't mentioned anywhere. Hope this helps.
FB.api('/' + friendlistID + '/members', 'post', {'members': members}, function(response) {
console.log(response);
if (!response || response.error) {
alert('Could not save members!');
} else {
alert('Members added to list!');
}
});

Simply change the endpoint, and the data you're sending.
The Graph Endpoint you're using is FriendList
friendlist_id = 1435134523451;
FB.api('/'friendlist_id+'/members', 'post', {members:'comma,separated,ids,of,friends,to,add,to,list'}, function(response) {
console.log(response);
if (!response || response.error) {
alert('Error occured');
} else {
alert('yay!');
}
});

I think
FB.api('/FRIENDLIST_ID/members?members=1,2,3', 'post', function(response) { … });
should do it.

Related

Problems with FB.api() posting and sending notifications

I cant seem to make a POST request or get this function to work, but I cant seem to do it and it gave no specific error. But here is the code
var body = 'Hello world on post';
FB.api('/100008601850848/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured' + response.error);
} else {
alert('Post ID: ' + response.id);
}
});
I dont have any information to give you because the error did not give me information and FB api documentation on it is not clear

Facebook Post image to Facebook fan page with Javascript

It's funny really...
This is my script
var imgURL = "http://onseiekoerant.com/upload/uploads/1411504661_2786.jpg";
FB.api('/'MY PAGE ID'/photos', 'post', {
message: 'Website Genius',
url: imgURL,
access_token: accessToken
}, function (response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
//alert('Post ID: ' + response.post_id);
}
console.log(response);
});
When I call this function, it returns te restponse the the POST_ID. It's suposed to be successfull, but nothing is on my facebook fan page.
To give additional info, the access token cames from my currently signed in user of facebook, which is admin of the page.
What am I missing?

params with fb js sdk

Hey guys am new to javascript facebook sdk .When i learn about the params in javascript i feel so confused.My code is
var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
This code works well ..But my doubt is that can we use the code like
var body = 'Reading JS SDK documentation';
FB.api('/me/feed?message=body', 'post', function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
Is there any problem with the second type of code ..Can it be done in Fb js sdk ..
Hope you guys can help me ..Thanx in advance
It works.. But Let me explain this a bit.
FB.api() method is declared as follows
FB.api(path, method, params, callback)
The method parameter given here is "post" which is equivalent to an html post.
As per the api documentation posting something to feed should be done with post method.
For a post method, to be on the safe side pass parameters through params
Lastly some javascript syntax. Here body is a variable so it should be FB.api('/me/feed?message='+body,... or the text body will be posted to your feed
Try out your code in the Test Console
See documentation for more details

FB API posting to feed

I have been stuck on this for a while.
I have the FB SDK working perfectly for everything; logging in, logging out, getting user pictures, etc. But I cant figure out this simple problem.
Why is this code alerting 'Error Occurred' and not what I want it to.
Post to Facebook
<script>
function postToFacebook() {
FB.api('/me/feed', 'post', { message: 'Test Message' }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response);
}
});
}
</script>
Thank you in advance!

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);
}
});
}

Categories

Resources