Facebook JS SDK check specific like of logged in user - javascript

I can't seem to check if a logged in user likes a specific Facebook Business page(URL). This keeps coming back as undefined. Notice anything wrong here?
function postLike() {
FB.api(
'https://graph.facebook.com/me/og.likes',
'get',
{ id: objectToLike,
privacy: {'value': 'SELF'} },
function(response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
document.getElementById('result').innerHTML =
'Business page is ' +
response.object + '</a>';
}
}
);
}

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?

Facebook story posting issue

I am setting up for posting story on facebook but I am getting following alert:
You, or this app's Open Graph Test User, must have published this action at least once.
I am getting id in the response but when I am clicking on that I am redirecting to "Page not found".
Here is my code :
FB.api(
'me/objects/appnamespace:objecttype',
'post',
{
object :{
app_id: myappId,
objectype: myurl,
title: "Sample Organization",
image: mylogo,
description: ""
}
},
function(response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
document.getElementById('result').innerHTML =
'<a href=\"https://www.facebook.com/me/activity/' +
response.id + '\">' +
'Story created. ID is ' +
response.id + '</a>';
}
}
);

How to get action id to delete previously posted action on timeline

I am using following code to post actions on timeline
<script type="text/javascript">
function read()
{
FB.api('/me/app_namespace:read' +
'?article=http://example.com/test.php&access_token=','post',
function(response) {
var msg = 'Error occured';
if (!response || response.error) {
if (response.error) {
msg += "\n\nType: "+response.error.type+"\n\nMessage: "+response.error.message;
}
alert(msg);
}
else {
alert('Post was successful! Action ID: ' + response.id);
}
});
}
</script>
Now i want to use the following code to delete action but the problem is dont know how to save the "action id" from above code so that it can be used in following code.
<script type="text/javascript">
function deleteAction()
{
FB.api(
'/actionid',
'delete',
function(response) {
alert('action deleted')
});
}
</script>
Thanks!
It depends, are you looking to delete the action in a later session or current? In the current session itself, you can probably simply store it in a variable. For eg:
function read()
{
FB.api('/me/app_namespace:read' +
'?article=http://example.com/test.php&access_token=','post',
function(response) {
var msg = 'Error occured';
if (!response || response.error) {
if (response.error) {
msg += "\n\nType: "+response.error.type+"\n\nMessage: "+response.error.message;
}
alert(msg);
}
else {
alert('Post was successful! Action ID: ' + response.id);
var idToDeleteLater = response.id;
}
});
}
function deleteAction()
{
FB.api(
'/'+idToDeleteLater,
'delete',
function(response) {
alert('action deleted')
});
}
As you can see, that's pretty straightforward, all you've done is stored the actionID in a variable. You can potentially store multiple IDs in an array or something.
On the other hand, if you want to delete the actions in a later session (unlikely for a "read" action), then you need to store these action IDs in a database or something, and pull the action from there prior to deleting.

(#3) App must be on whitelist facebook

I'm trying to post a messsage to a wall using FB.api
My perms are: 'email, read_stream, publish_stream' and my code is:
FB.getLoginStatus(function(response){
if(response.session) {
var accessToken = response.session.access_token;
var tokenUrl = "https://graph.facebook.com/me/feed?access_token=" + accessToken + "&callback=?";
var shareUserId = document.getElementById("shareHidden").value;
var shareTxtAreaMsg = document.getElementById("shareTxtArea").value;
console.log("friends user Id: " + shareUserId + " & " + "message: " + shareTxtAreaMsg);
var data = {
message: "shareTxtAreaMsg",
display: 'iframe',
caption: "Caption",
name: "Name",
picture: 'http://someDomain.com/Dev/img/share-force-wall-img.jpg',
link: "http://www.facebook.com/pages/someapp/XXXXXXXXXXX?sk=app_XXXXXXXXXXXXXX", // Go here if user click the picture
description: "Description field",
actions: [{ name: 'action_links text!', link: 'some link' }],
}
console.log(accessToken);
FB.api(tokenUrl, 'post', data, function(response){
if (response)
{
//console.log(response);
if (response.error)
{
console.log(response.error.message);
}
else
{
if (response.id)
console.log("Posted as post_id "+response.id);
else if (response.post_id)
console.log("Posted as post_id "+response.post_id);
else
console.log("Unknown Error");
}
}
});
}
});
When when try to post the message I'm getting a "(#3) App must be on whitelist" returned. Why is this happening?
Try FB.api('/me/feed'... instead of tokenUrl because FB.api will automatically add the full url prefix.

Categories

Resources