-7

I have implemented the invite box of facebook from facebook-invite-friends-api, but i am not able to get how they redirect to my website as they(9lesson) have shown in demo from the facebook notification. Please help me how can i do it.

My code is:

 <div id="fb-root">
</div>
<a href="javascript:void(0);" onclick="FbRequest('If you want to fulfill your wishes then do not miss the opertuanty, huury up and join WishIsDone, A platform where you can fulfill your as well as your friends wishes...!','609416079110673');">
    Send Request</a>
<script type="text/javascript">
    function FbRequest(message, data) {
        FB.ui({ method: 'apprequests', message: message, data: data, title: 'Share this site with your friends' },
            function (response) {
                // response.request_ids holds an array of user ids that received the request
                var receiverIDs;
                if (response.request) {
                    var receiverIDs = response.to;  // receiverIDs is an array holding all user ids
                    alert(receiverIDs);
                }
            }
    );
    }
    // typical application initialization code for your site
    (function () {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    } ());
    window.fbAsyncInit = function () {
        FB.init({
            appId: '******',
            session: {},
            status: true,
            cookie: true,
            xfbml: true

        });
    };

</script>

My login page code:

 <script type='text/javascript'>
    if (top.location != self.location) {
        top.location = self.location
    }
</script>
Ram Singh
  • 6,664
  • 35
  • 100
  • 166

1 Answers1

3

Basically, when a user clicks on one of the invites, they are sent to your application's canvas URL. The one you set in your application's settings.

The user will be sent to your application and from there you can redirect them to your actual site using a JavaScript redirect as they do in the tutorial you linked to:

The following code is for breaking Iframe, include this code into your webpage.

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

When they say "breaking Iframe" they mean to take the content out of the Iframe and into it's actual URL (silly wording... I agree). Note the use of top.location. This will change the location of the top most frame - in this case, it is apps.facebook.com.

Lix
  • 47,311
  • 12
  • 103
  • 131
  • i have added the above code in the login page but i am not able to get the required result... – Ram Singh Oct 30 '13 at 12:05
  • Are there any JS errors in your console? Is the user actually arriving at the login page? – Lix Oct 30 '13 at 12:06
  • i have used alert to check that but it is fire alert even.. so i can not say it is arriving on the login page.. but i have set it as the default page for my website. and entered the canvas url as :: http://subdomain.domian.com/foldername/ – Ram Singh Oct 30 '13 at 12:08
  • If Facebook is not sending you to the correct login page then you have made some mistake with the url you've set... Please double check that the canvas url is correct... Can you post the canvas link here? – Lix Oct 30 '13 at 12:09
  • it is "http://" wishisdone.visionswebsites.com/wishisdone/" i have added " after // to show you properly the url – Ram Singh Oct 30 '13 at 12:11
  • Ok - I see it now... And this URL is what is set inside your canvas URL? When a user clicks on a notification - do they see this page? – Lix Oct 30 '13 at 12:35