agorapulse / grails-facebook-sdk

Facebook SDK Grails Plugin
http://agorapulse.github.com/grails-facebook-sdk/guide
30 stars 13 forks source link

Acces Friend Facebook Id in sendLink Callback? #60

Closed confile closed 11 years ago

confile commented 11 years ago

How can I access the friends facebook id in the callback function? If I cannot get the friend id in the callback function I cannot react on it. I tried to get attribute properties with $(this).attr() but this does not work.

<script>
    function someCallbackFunction(response) {
        alert('callback called!');
        if (response && response.success) alert('Sent successfully');
        console.log(response);
    }
</script>
<facebook:sendLink
    callback="someCallbackFunction"
    link="http://www.google.com"
    to="594317994">
    Send a link to a friend
</facebook:sendLink>
benorama commented 11 years ago

Have you tried jquery HTML5 data method ? Ex.: $('#myShareLink').data('to')

confile commented 11 years ago

You cannot apply this, if you have, as usual, a list of friends. Consider a list of friends, where each list itam has a sendLink button. Then you cannot determine what is the correct fried uuid?

benorama commented 11 years ago

Sorry, I do not have much time to dig into this, but you should be able to get a reference to the link (with response.target?) Since, this is not linked to Grails Facebook SDK but to JS/jQuery, I close this issue.

confile commented 11 years ago

@benorama response.target gives undefined. I am woundering if this is an issue with you plugin?

benorama commented 11 years ago

Here is the code which is executed (in web-app/js/send-link.js):

FB.ui(options, function(response) {
        if (link.data('callback') != undefined) {
            var callback = window[link.data('callback')];
            if (typeof callback === 'function') {
                callback(response);
            }
        }
    });

So you might try to edit it to add a second parameter link to the callback function.

FB.ui(options, function(response) {
        if (link.data('callback') != undefined) {
            var callback = window[link.data('callback')];
            if (typeof callback === 'function') {
                callback(response, link);
            }
        }
    });

Then in your gsp

function someCallbackFunction(response, link) {
        alert('callback called! Message to:' + link.data('to'));
        if (response && response.success) alert('Sent successfully');
    }

Let me know if it solves your issue.

confile commented 11 years ago

Your solution might be more elegant. I solve it in a different way. I hide the sendLink and had another element with a click handler on the page. When I click this element I store the ui in a hidden input field and trigger the click command on sendLink. This way the callback can access the hidden input and gets the uid of the clicked facebook user.