Saturday 3 November 2012

FACEBOOK: INVITE FRIENDS API for your website.

Have you noticed 'bring your friends' button or link on web pages? Want to add it to your website and let users invite their facebook friends? This is how you do it!
Invite facebook friends API
www.techoyo.com                              (c) Ganesh Venkataraman


First, u need to have a facebook APP. If don't have one, have a look at
this Create your Facebook APP for website.


Now, you also need to add Canvas for your APP. This is how you do it by editing APP information:


Click on 'save changes' button.
Now, place this code in your web page:

<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>

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

You must change 'APP_ID' in the above code.
You can also change the 'Your message dialog' as desired.

Code IFrame
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>

You are done now. This is what you'll see as an invite screen on clicking the link on your website:




DEMO LINK CLICK HERE!

15 comments:

  1. You are awesome man...

    But please help me I have this error

    API Error Code: 191
    API Error Description: The specified URL is not owned by the application
    Error Message: redirect_uri is not owned by the application.

    ReplyDelete
  2. ^Many come up with this problem. If you use the code on local host, the code won't work. That is because in your set up, you would have specified redirect_uri as your site URL. If you upload it to your server, it should work fine. If you want it work on local host, make site URL : http://localhost:8080/

    ReplyDelete
    Replies
    1. http://localhost:8080/ is also not working, any localhost url is not working. so is it compulsory to have website hosted for fb invite friends on website?

      Delete
  3. Hello, thank you for your code,
    I have problem, I have the popup and I can choose friends and confirm send request but no thing happens ! request don't arrive to friends

    have you any idea please ?

    ReplyDelete
    Replies
    1. Probably you don't have a SSL certificate for the website that you are running your code on.

      Delete
    2. Thank you for your answer, yes that's true I don't have a SSL certificate for the web site,
      by modifying some parameters in the app configuration, friends have the notifiaction of the request but there are nothing, the page contain just the header of facebook and no others information,
      sorry may be I'm not very clear in my explication, that's the first time I work with facebook application :),
      thank you.

      Delete
  4. i use this and send invite but that invite view the person that time error come that is
    Error code: ssl_error_rx_record_too_long

    ReplyDelete
  5. Hi please check this here is a running script of facebook invite friend api with example.. http://phpsollutions.blogspot.com/2014/02/facebook-invite-friends-api-in-php.html

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. it opens up the dialog box but with a msg that "Game Requests are only available to games.".
    what should i do?? please help

    ReplyDelete
  9. Error : Game Requests are only available to games.
    please help me

    ReplyDelete
  10. Very entertaining information. found a lot of things for yourself useful. denver air conditioning repair

    ReplyDelete
  11. Hello Admin, thank you for enlightening us with your knowledge sharing. PHP has become an inevitable part of web development, and with proper PHP training in Chennai, one can have a strong career in the web development field.

    ReplyDelete