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

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.

Related

facebook apprequests dialog error “An error occurred. Please try again later.”

I was searching all possible topics but now solution works for me.
There is my code, which works in all browsers except Chrome. There is just window with An error occurred. Please try again later..
It is identical code from FB documentation.
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : {$appId},
frictionlessRequests: true
});
function sendRequestViaMultiFriendSelector() {
FB.ui({ method: 'apprequests',
message: '{_"FACEBOOK_INVITE_WINDOW_MESSAGE"}'
}, requestCallback);
}
function requestCallback(response) {
//callback code
}
</script>
<a onclick="sendRequestViaMultiFriendSelector(); return false;">
This might be because your application is still in sandbox mode.
You have to specify the display option for the dialog ('popup, 'iframe'...)
For example:
FB.init({
appId : {$appId},
frictionlessRequests: true,
display: 'popup'
});
You have not stated if your application is on Facebook or not. The reason this is important is because of the canvas_url parameter of your application settings. If you are on apps.facebook.com/app_namespace, then you'll already have this field filled out. However some projects simply do not operate on Facebook itself. In such cases people don't really "need" to fill in this parameter. It is however necessary for app requests to work.
When a user acts on an application request (IE accepts it), they are redirected to the canvas url of that application. Not specifying the canvas url can nullify the request. This might also be the reason for the error.
Try setting your canvas url. You can even have it redirect to your proper URL, it doesn't have to "do" anything else.

Facebook-login issue

This is our link for the fb or old way sign-in: http://www.greeceinsiders.com/login
Does the fb-login work to you? When I click it it redirects me to the same page.
Sometimes it works sometimes not. When a user logs in with fb we collect his vredentials sucha as email,city, name in our mysql database. Does anybody had the same problem? Is there any good tutorial out there, that explains it step by step and is for the current fb api?
Any suggestions or feedback is welcome, thank you! Some code
FOUND IT!
I like to use the FB.login method. This allows me to set the permissions that I want (such as email) and access the info on my server through a Facebook library like https://github.com/facebook/php-sdk. There are also good tutorials on https://developers.facebook.com/docs/authentication/:
FB.login(
function(response) {
if (response.authResponse) {
$.ajax({
url: Global.base_url + 'user/facebook_log_in/',
dataType: 'json',
success: function(data) {}
});
}
else {
// Display facebook error
}
},
{
scope: 'email'
});

This comment has not yet been published to 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>

Facebook OpenGraph - issues with Activity Plugin

I've been able to post activities to my personal wall and timeline, but I don't seem to be able to get the Activity Plugin to go no matter how I call it. I get a success when I call it, and have also been getting a success code from the command line CURL calls.
<script type="text/javascript">
function postAttend()
{
FB.api('/me/kaplangraph:attend' +
'?class=http://samples.ogp.me/253928254644843','post',
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post was successful! Action ID: ' + response.id);
}
});
}
</script>
This I know is working. I see them on my personal timeline. I can't however pull them up in the Activity Plugin. All of the following show up blank. Am I missing something?
<fb:activity action="kaplangraph:attend"></fb:activity>
<fb:activity actions="kaplangraph:attend"></fb:activity>
<fb:activity actions="kaplangraph:attend" app_id=253477038023298></fb:activity>
<fb:activity app_id=253477038023298></fb:activity>
<fb:activity site_url="https://severe-winter-5145.herokuapp.com/"></fb:activity>
Thanks guys, I also posted to the FB developer group ... hoping to get an answer there.
I will post if I find anything, but I agree this is a bug and not a beta issue. It says in the example that this will work for devs/admins/etc ... just not the world. I am guessing somehow in the transition they killed the activity feed, as I am having trouble with others as well.
The Facebook timeline and new open graph are still in beta. I'm pretty sure it won't show up in the activity plugin until it is out of beta.
I think this is a bug; Yes, they are in beta, but the tutorial makes no mention of the fb:activity not working. It is also unclear what parameters should be passed (action or actions). I too have tried various ways of trying to get fb:activity to work, but for now I am waiting to see if there is any update to address this issue.

Hide content from non-fans in a Facebook *IFrame* (Not FBML)

it is incredibly easy to hide content from someone who does not like your application...if you're using FBML. I'm using an iFrame and the JavaScript SDK, and am having terrible difficulty figuring this out.
The behavior I'm seeing (both logged in and out) is that does not seem to be supported by FB.XFBML.parse(). Am I mistaken or is there an alternative method I can use that does not require the user to give explicit permission?
Finally figured it out!
After you have initialized the api (using FB.init()) simply do the following:
FB.api('/mypage', function (response) {
FB.api({ method: 'pages.isFan', page_id: response.id },
function (response) {
alert(response);
});
});
When the '/mypage' response comes back, it has the page id of the profile. Use that in the pages.isFan call and it will return a boolean object telling you if the current user has Liked that page or not.
No need to deal with authentication, extended permissions, or any FQL.