Cant send a FB notification using FB.api() - javascript

I am trying to send a notification via FB.api() and everything I am doing fails. I have not added any permissions besides the default permissions, just in case that is the issue I am putting that out there. Now here is my code before I continue on
FB.api('/100008601850848/notifications', 'post',
{
access_token: APP_ACCESS_TOKEN,
template: "This message should appear",
href: REDIRECT_URL,
},
function(response) {
if (!response || response.error)
{
console.log("Error" + response.error);
}
else
{
alert("It worked");
}
});
But it doesn't work. And the error doesn't show. Its just [object Object] how can I post 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?

adding Facebook friends to a friendlist with FB.api

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.

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