This comment has not yet been published to Facebook - facebook

I am using FB:Comments on my page using XFBML. When I post a comment, an error comes up with the message "This comment has not yet been published to Facebook"
This is the code that I am using apart from the fb:comments tag
<div id="fb-root"></div>
<script>window.fbAsyncInit = function() {
FB.init(
{appId :'APP ID',status:true,cookie:true,xfbml:true});
};
(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>

It looks this problem comes with ".info" domains.
Or it might be that this happens with top level domains with 4 or more letters, like .info, .name or .mobi, though I haven't investigated into all of them.

What attributes do you have set on the fb:comments tag? I believe all that's doing is the facebook connect/login side of things. Have you got the correct OG tags in place? You could also add in code to subscribe to the add comment event and see what's going on:
<script>
FB.Event.subscribe('comments.add', function(resp) {
for(var i in resp){
if(resp.hasOwnProperty(i)){
console.log(i + " " + resp[i]);
}
}
});
</script>
you may also need the channel file as detailed here https://developers.facebook.com/docs/reference/javascript/

I'm having the same problem. If I use the example page (http://developers.facebook.com/docs/reference/plugins/comments/) the comment gets posted on my wall, whereas doing the same in the comment box of my app does not, unless I pint them to a Facebook URL.
This works:
<fb:comments href="http://www.facebook.com/any-url/" ></fb:comments>
This doesn't if I do it from my app, but it works if I do it from my site (which doesn't really help for the purpose I need it to)
<fb:comments href="http://www.mysite.com/any-other-url/" ></fb:comments>

Related

Display something for people who like or not like our facebook page

I search a solution for the problem highlighted in this question.
Unfortunately, the accepted solution (which dates back to 21/11/2012) doesn't work anymore, as you can this in this demo.
Does someone know why?
Body
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '179378788777832',
status : true,
cookie : true,
xfbml : true
});
</script>
<div id="login">
You are not logged in to FB, Please click here to login.
</div>
<div id="container_notlike">
YOU DONT LIKE
</div>
<div id="container_like">
YOU LIKE
</div>
JS
var hideLogin = function(){
$("#login").hide();
}
var showLogin = function(){
$("#login").show();
}
var doLogin = function(){
FB.login(function(response) {
if (response.session) {
hideLogin();
checkLike(response.session.uid)
} else {
// user is not logged in
}
});
}
var checkLike = function(user_id){
var page_id = "40796308305"; //coca cola
var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
var the_query = FB.Data.query(fql_query);
the_query.wait(function(rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
$("#container_like").show();
//here you could also do some ajax and get the content for a "liker" instead of simply showing a hidden div in the page.
} else {
$("#container_notlike").show();
//and here you could get the content for a non liker in ajax...
}
});
}
$(document).ready(function(){
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
hideLogin();
checkLike(response.authResponse.userID)
} else {
showLogin();
}
});
$("#login a").click(doLogin);
});
CSS
body {
width:520px;
margin:0; padding:0; border:0;
font-family: verdana;
background:url(repeat.png) repeat;
margin-bottom:10px;
}
p, h1 {width:450px; margin-left:50px; color:#FFF;}
p {font-size:11px;}
#container_notlike, #container_like, #login {
display:none
}
I search solution for hours but I didn't find anything what works.
Thank you for help.
Like Gating is not allowed anymore, that´s why it is not possible. The only reliable way to get that information is by authorizing a user with the user_likes permission and using /me/likes/[page-id]. But you will not get that permission approved for like gating in the Login Review.
People need to like something because they really want to, not because they get something for it:
Only incentivize a person to log into your app, enter a promotion on your app’s Page, or check-in at a place. Don’t incentivize other actions
Source: https://developers.facebook.com/policy/
Btw, you can also subscribe to the edge.create event to find out if a user just clicked your like button, but you can´t find out if the user liked it before: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/
The problem on that code is that FQL is deprecated .
You can't do what you want to, and thats why changes are necessary .
Your code would work if your app is old, created before changes that turns like gating not allowed, but anyway, you cannot use that for show content. You can use that kind of implementation for creating an interactive experience, where you can for example changing the content, saying "Thanks for liking".. Or "Connect with us, liking our page.." ..
You can also think about interfaces, where you show up the page plugin, and just after user likes, you say Thank you ... and hide the page plugin ... But user must always be able to close without liking .
For checking if user likes a page, you need use :
FB.api get on '/me/likes', and with the response ...
if (response.data[likes].name == "Coca-Cola")
or... better
if (response.data[likes].id == "40796308305") {
}
I repeat, One thing has nothing to do with another ..
You can check if user likes a page, but you cannot restrict content, based on this kind of resource .
There are other ways to check it, for exaple :
Get api call to userid/likes/pageid returns page info if user likes the page, and returns nothing if user does not like the page .
You will waste time trying do that for controlling content consumption .
Your app must be aprooved for asking user_likes permission, and its better you think about creating another experience for users, instead of submitting something like that .
I also think that content with good open graph for sharing, commenting and optional liking is very much more efetive, because i noticed that many people used to like and dislike the page after getting the content .
If you just... Prompt a FB.UI for sharing after 1 minute, for example, you will have much more results .. Aways positioning the page plugin in strategic places, people will naturally like your page ..
Than you can say change the page plugin element :
Thank you for liking, please share with your friends ....
Who would also like ...
Or use a callback for triggering the share dialog ..
OLD SCHOOL API CALL
The method FB.Event.subscribe() allowed apps to subscribe to a range of events, and define callback functions for when they fire, is deprecated .
Also FQL Query is deprecated .
For checking if user likes a page, you need user.likes permission, so you can try :
FB.api get on '/me/likes', and with the response ...
if (response.data[likes].name == "Coca-Cola")
or... better
if (response.data[likes].id == "40796308305") { }
There are other ways to check it, for exaple :
Get api call to userid/likes/pageid returns page info if user likes the page, and returns nothing if user does not like the page .
You can check if user likes a page using this call, but you cannot restrict content, based on this kind of resource .
2018 UPDATED SOLUTION
But nowadays, in 2018 the best method for is setting Webhooks .
Webhooks are a subscription based system between Facebook and your server. Your app subscribes to receive updates from Facebook via a specified HTTPS endpoint .
This allows your to app to receive notifications whenever there are updates to a chosen set of topics and their fields, so, you can track changes to most sections of the user's profile, such as About, Photos, Posts, Friends, and Likes.
Webhooks update notifications are sent as POST requests to a callback URL that you supply. Notifications can be lightweight, indicating only that a field has been updated, or can include the newly updated value .
webhooks user reference
Full list of user profile fields that you can subscribe to, such as About, Photos, Posts, Friends, and Likes.
webhooks page reference
The easiest way to set up your app to receive Webhooks updates is to use the App Dashboard's, check out Facebook Platform documentation for more info .
Webhooks documentation

facebook send API Error Code: 100 API Error Description: Invalid parameter Error Message: 'link' is invalid

I am using facebook post GRAPH UI for posting private message with link to my application in facebook.
Earlier it was working fine but from last two days the dialog started throwing error as :
An error occurred. Please try again later.
API Error Code: 100
API Error Description: Invalid parameter
Error Message: 'link' is invalid.
for sending message I am using code :
function sendMessage(id) {
FB.ui({
method : 'send',
name : 'My APP',
link : 'https://apps.facebook.com/MY_APP/',
to : id,
show_error : 'true',
description : 'my description'
});
}
I have Googled about this and only relevant information I get is that facebook is blocking the link to its own domain as to avoid spam.
as I change the link to other live site its working.
I need to send link to my application as I have to provide such functionality.
I've had similar issues, and figured I'd share the results of my investigation here.
The only information in the Facebook documentation describing the link parameter is not terribly helpful:
link -The URL that is being sent in the message.
There are a couple other StackOverflow questions similar / related to this one:
Facebook API Error 100 - invalid link
this problem ended up being a malformed picture parameter
Facebook FB.ui send dialog intermittently returns invalid link error -
"The issue revolved around our url being dynamic and needing force caching each time. I now make an ajax call to "https://developers.facebook.com/tools/debug/og/object" to refresh it and then launch the send dialog."
I still don't know precisely what constitutes a valid link parameter, but...
Making some inferences from the above questions & responses, as well as some testing on my part, valid link parameters:
Must be "fully qualified". I.E. containing http:// or https://
Must not be facebook.com links
Might not like redirects (or you have to be sneaky with them)
Do support URLs not in the "App Domains" list
Do support Query Strings
May be finicky regarding dynamically generated pages (as in this question)
Apparently Facebook has some sort of link crawling mechanism that performs some unknown tests on a link parameter to determine its validity. I only wish they would choose to document it for us.
Found a solution:
Facebook Send Dialog Error Code: 100 API Error Description: Invalid parameter Error Message: ‘link’ is invalid.
Problem Cause:
Facebook is not allowing to use its own link as to stop spamming.
Problem Solution:
There is as such no solution as its bared by Facebook API.
Other workout:
Shorten URL, but its didn’t works as Facebook check the provided URL.
Redirect URL, same as above.
In my case I have deployed an additional HTML page just use to redirect to the Facebook App link.
Just remember that you should have a timer for few seconds as Facebook scans the provided URL, so it wont be able to detect that the page is redirecting to same Application Link.
I have used the following code for my HTML file:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My Application</title>
</head>
<body>
<p id="demo"></p>
</body>
<script type="text/javascript">
var url = "https://apps.facebook.com/MY_APPLICATION_ID";
var myVar = setInterval(function() {
myTimer()
}, 1000);
var counter = 3;
function myTimer() {
if (counter == 0) {
window.location.replace(url);
window.clearInterval(myVar);
}
document.getElementById("demo").innerHTML = "you will be redirected in "
+ counter + " seconds...";
counter = counter - 1;
}
</script>
</html>
I had the exact same problem except that my link was pointing to my website.
In case someone is in a similar scenario please check at this solution. Hope that will help some people.
If bad parameter occurs and and message reads "API Error Code: 100" - Make sure the box beside "Share with playlist starting from" is unchecked in youtube and that error won't show.

getting notification when someone comments using comments plugin

So I have an iFrame app on a fan page, which includes the comments plugin. Is there a way I/any admin can receive a notification or email every time someone adds a comment?
You can subscribe to comment.create event and send the notification to admin in any way you prefer, once comment is created. Facebook itself doesn't provide such functionality.
This may looks like this (I assume Facebook JavaScript SDK is already loaded on page before doing this, read about it in documentation on Loading, anyway if you're using Social Comments Plugin it should be loaded already):
<script type="text/javascript">
FB.subscribe('comment.create', function(response){
// Here you need to do a call to some service/script/application
// to notify your administrator about new comment.
// I'll use jQuery ajax to call server-side script to illustrate the flow
$.post('//hostnamne/path/to/script', {
"action": "comment created",
"url_of_page_comment_leaved_on": response.href,
"id_of_comment_object": response.commentID
});
});
</script>
In your script located at http(s?)://hostnamne/path/to/script you can send a notification to admin, how to do it may vary on way you want it for example if you want to send an email you can use something like this php sample (aging this is just a flow sample, not real code you should use):
<?
$admin_email = 'root#localhost';
$commentID = $_REQUEST['id_of_comment_object'];
$page_href = $_REQUEST['url_of_page_comment_leaved_on'];
$message = "comment #{$commentID} was leaved on page {$page_href}";
mail($admin_email, "You have a new comment", $message);
?>
If you need to track the deletion of comments too you can use comment.remove event with similar flow...

Facebook wall posts

I need some help please. I've been lost in the graph facebook documentation for the last 2 hours. Please send an advice about how could I get my facebook wall posts/info, etc . . . ? I need an access token. I've tried in many ways to get it, but is useless. I don't understand how to build that url . . . Please, just tell me from where should I start? Thank you!
It's not very clear what you are trying to do or what language you are trying to do this in. But the graph api isn't very difficult to tackle if you follow their documentation. You need to first prompt the user to authenticate with your application and any extended permissions. Then you can make calls to the graph api (or FQL queries if needed).
Here is a full example of getting Facebook wall posts like you asked. Reading wall posts will require the read_stream extended permission.
<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
Get Feed
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({ appId : 'yourFacebookAppId', status : true, cookie : true, xfbml : true });
function getFeed() {
FB.login(function(response) {
if (response.session && response.perms) {
FB.api('/me/home',
function(response) {
alert(response.data.length);
for (var i = 0; i < response.data.length; i++) {
alert("message from " + response.data[i].from.name + ": " + response.data[i].message);
}
}
);
}
} , {perms:'read_stream'});
}
</script>
</body>
</html>
This can also be done in server code like PHP but for generic questions like this and first getting started the javascript api is probably the easiest until you know more of what you are trying to do.
https://developers.facebook.com/docs/authentication/
Facebook Platform uses the OAuth 2.0 protocol for authentication and authorization. We support a number of different OAuth flows that you can use within your Website, mobile and desktop apps.
This document outlines that different mechanisms Facebook Platform uses to support each of these flows. The examples in this document use PHP for server-side programming and HTML/JavaScript for client-side code. These examples are very straightforward and easily translatable to other languages.
This is where you need to start.
try this one https://graph.facebook.com/USER_ID/feed?access_token=TOEKN
Just replace the USER_ID and TOKEN with the users id and access_token and you'll get a list of all the wall posts in a json format and also you can navigate the result page using the Previous and Next link at the bottom .
Hope that will solve your problem .

FB.event.subscribe('comment.create') doesn't work

I am trying to get a notification when an user comments using the social plugin. The code is as following:
<fb:comments href='someurl' width='400'></fb:comments>
FB.Event.subscribe('comment.create', function(response)
{
alert(response);
}
Simple, but it's not working. Someone got some possible errors? From my research online, it seems as if the notification has no real consistency. Sometimes it works, sometimes it doesn't.
Add the notify="true" attribute to the fb:comments tag.
<fb:comments notify="true" href='someurl' width='400'></fb:comments>
FB.Event.subscribe('comment.create', function(response)
{
alert(response);
}
why not to close the function call?
FB.Event.subscribe('comment.create', function(response)
{
alert(response);
});
I was having the same issues until I stumbled upon this answer here:
Methods subscribed via FB.Event.subscribe to comment.create or comment.remove are not triggered
You should put everything related to FB.[...] functions (FB.init,
FB.Event.suscribe, ...) in
window.fbAsyncInit = function(){
// Your code });
Otherwise your code will be parsed before the FB js sdk has been fully loaded and you will >never really suscribe to
your event
That might be obvious to a lot of people but for me and others who are new to this that might trip you up.