How can I invite friends from facebook using fb_graph?

Basically, I want to display a list of friends (with images and names) and invite them to my application, which I create on rails with the fb_graph . The link shows how this will work, basically you click the "Invite Friends" button, and the list of friends appears using the button that allows you to invite the corresponding user.

http://www.quora.com/User-Acquisition/What-is-the-best-invite-a-friend-flow-for-mobile

Is there any way to do this with fb_graph ?

+4
source share
4 answers

You put. Assuming you have a working implementation of fb_graph, you can get a list of friends with the following command (from https://github.com/nov/fb_graph ):

 FbGraph::User.me(fb_token).friends 

You can use this to create your user interface for your friends list and then invite selected friends, for example (unverified modification from the previous link, as well as https://developers.facebook.com/docs/reference/dialogs/requests/ ):

 app_request = FbGraph::User.me(token).app_request!( :message => 'invitation message', :to => friend.uid ) 

The previous code may also accept a comma-delimited UID collection.

I will leave you to create and code the user interface, but this is possible using fb_graph. These two links should be solid gold if you decide to expand the scope.

+9
source

Thank you for your interest in my gem.

The Brad Werth code works for existing users (= already installed users), but probably not for new users.

There are many restrictions for sending application requests in the background to avoid spam. This limitation directly affects the sending of the fb_graph application request function.

If you are developing an iOS application, I recommend that you use the official iOS SDK for FB. https://developers.facebook.com/docs/howtos/send-requests-using-ios-sdk/

Using the iOS SDK (or JS SDK in the html5 app), you have less restrictions.

ps. I am not familiar with the development of the Android App and the official Android SDK for FB, but I assume that they have something similar in their Android SDK.

+3
source

Of course, Facebook provides a beautiful dialog box for choosing friends to whom you want to send requests. But there is also a good javascript built-in tool with which you have the same Facebook friend selection dialog.

JQuery Facebook Multi-Friend Selector Plugin

This plugin will make a call to the Graph API on Facebook and collect your friends list. The advantage of this plugin is that it will load the list of all friends in "lazy boot mode".

+1
source

This may help, I used it on my PHP server and it worked.

This code helps you send, send messages, and send requests to your friends.

Main tag:

 <script type="text/javascript"> function logResponse(response) { if (console && console.log) { console.log('The response was', response); } } $(function(){ // Set up so we handle click on the buttons $('#postToWall').click(function() { FB.ui( { method : 'feed', link : $(this).attr('data-url') }, function (response) { // If response is null the user canceled the dialog if (response != null) { logResponse(response); } } ); }); $('#sendToFriends').click(function() { FB.ui( { method : 'send', link : $(this).attr('data-url') }, function (response) { // If response is null the user canceled the dialog if (response != null) { logResponse(response); } } ); }); $('#sendRequest').click(function() { FB.ui( { method : 'apprequests', message : $(this).attr('data-message') }, function (response) { // If response is null the user canceled the dialog if (response != null) { logResponse(response); } } ); }); }); </script> 

Body tag:

 <body> <div id="fb-root"></div> <script type="text/javascript"> window.fbAsyncInit = function() { FB.init({ appId : 'xxxxxxxxxxxxxxxxxxx', // App ID status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true // parse XFBML }); // Listen to the auth.login which will be called when the user logs in // using the Login button FB.Event.subscribe('auth.login', function(response) { // We want to reload the page now so PHP can read the cookie that the // Javascript SDK sat. But we don't want to use // window.location.reload() because if this is in a canvas there was a // post made to this page and a reload will trigger a message to the // user asking if they want to send data again. window.location = window.location; }); FB.Canvas.setAutoGrow(); }; // Load the SDK Asynchronously (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> <header class="clearfix"> <?php if (isset($basic)) { ?> <p id="picture" style="background-image: url(https://graph.facebook.com/<?php echo he($user_id); ?>/picture?type=normal)"></p> <div> <h1>Welcome, <strong><?php echo he(idx($basic, 'name')); ?></strong></h1> <p class="tagline"> This is your app <a href="<?php echo he(idx($app_info, 'link'));?>" target="_top"><?php echo he($app_name); ?></a> </p> <div id="share-app"> <p>Share your app:</p> <ul> <li> <a href="#" class="facebook-button" id="postToWall" data-url="<?php echo AppInfo::getUrl(); ?>"> <span class="plus">Post to Wall</span> </a> </li> <li> <a href="#" class="facebook-button speech-bubble" id="sendToFriends" data-url="<?php echo AppInfo::getUrl(); ?>"> <span class="speech-bubble">Send Message</span> </a> </li> <li> <a href="#" class="facebook-button apprequests" id="sendRequest" data-message="Test this awesome app"> <span class="apprequests">Send Requests</span> </a> </li> </ul> </div> </div> <?php } else { ?> <div> <h1>Welcome</h1> <div class="fb-login-button" data-scope="user_likes,user_photos"></div> </div> <?php } ?> </header> 
+1
source

All Articles