1

I've been working on this for a few days and I can't find what's missing. Does anyone have any advice?

It seems like its missing something but I have no idea what it would be.
I'm not receiving any errors. The share button works (to share to your own wall) but the invites don't appear to do anything at all.

I've replaced my appid with X's.

<html>
<head>
    <title>App Name</title>
</head>
<body>
    <div id="fb-root"></div>
    <script>
        var publish = {
            method: 'stream.publish',
            display: 'popup', // force popup mode
            attachment: {
                name: 'Connect',
                caption: 'The Facebook Connect JavaScript SDK',
                description: (
                    'A small JavaScript library that allows you to harness ' +
                    'the power of Facebook, bringing the user\'s identity, ' +
                     'social graph and distribution power to your site.'
                ),
                href: 'http://app-address.com/'
            }
        };
        function publish1() {
            FB.ui(publish);//, Log.info.bind('stream.publish callback'));
        }
    </script>
    <button class="btn" id="send-to-many">Send to Many</button>

    <button onclick="publish1()">Click</button>
</body>

<script>
    window.fbAsyncInit = function() {
        console.log('Initing facebook...');
        FB.init({
            appId: 'xxxxxxxxxxxxxxx', 
            status: true, 
            frictionlessRequests: true,
            cookie: true,
            xfbml: true
        });
        console.log('... done');
    };
    (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);
    }());

    document.getElementById('send-to-many').onclick = function() {
        FB.ui({
            method: 'apprequests',
            message: 'This is a test of the App-Name invite.'
            }, requestCallback);
            function requestCallback(response)
{
if(response && response.request_ids) {
     // Here, requests have been sent, facebook gives you the ids of all requests
     //console.log(response);
     location.href='home';
} else {
     // No requests sent, you can do what you want (like...nothing, and stay on the page).
}
}
}
</script>
</html>
  • Do you have a canvas url set for your application? – Lix Dec 11 '13 at 23:15
  • 1
    This bug should happen to all apps. Please, do not create another `birthday` application. – Andre Pena Dec 11 '13 at 23:17
  • It's not a **birthday** app but thanks for the insight. – Visible-Will Dec 11 '13 at 23:56
  • I don't have a canvas url. The page isn't on facebook. We're just using them for login and authentication. Does that make any difference? @Lix – Visible-Will Dec 11 '13 at 23:58
  • Yes. It does. When people click on a request, they are sent to the applications canvas url. If you haven't got one, the notification is sort of canceled out because Facebook can tell right away that there is no canvas url present. Even if you don't use it, you should place a holder there and possibly redirect from that URL to your site (or wherever the application is). – Lix Dec 12 '13 at 00:04
  • Take a look at [my answer here](http://stackoverflow.com/questions/11831890/apprequest-doesnt-send-the-notification/11885672#11885672). I'm talking about an android application but the exact same answer could go for anyone wanting to use app requests. – Lix Dec 12 '13 at 00:07
  • Does the Canvas link need to point to anything in particular or could it simply point to my login page? @Lix – Visible-Will Dec 12 '13 at 00:26

2 Answers2

0

Your code is looking fine. There must be a error in your facebook app setting. For invite function you have to give 'Canvas URL' & 'Secure Canvas URL' in your facebook app setting. You can also try with my codes below. This is a very simple code to implement.

<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'APP_ID',
cookie:true,
status:true,
xfbml:true
});

function FacebookInviteFriends()
{
FB.ui({
method: 'apprequests',
message: 'Your Message diaolog'
});
}
</script>


//HTML Code
<div id="fb-root"></div>
<a href='#' onclick="FacebookInviteFriends();"> 
Facebook Invite Friends Link
</a>

Here you have to write one more javascript code for breaking the iframe. So that the link 'll not open inside the facebook. You also have to write this same js code in your home page or any other page of your website, that you want your app to redirect.

<script type='text/javascript'>
if (top.location!= self.location)
{
top.location = self.location
}
</script>

For any further doubt feel free to write here.

Sourav
  • 29
  • 4
0

I had a similar problem and found that you have to click the DONE button. This is a form and the DONE button submits the form.

t q
  • 4,593
  • 8
  • 56
  • 91