2012-08-29 24 views
4

基本上我想显示一个朋友列表(包括图片和名字),并邀请他们到我的应用程序,我创建的轨道与fb_graph宝石。该链接显示了这将如何工作的流程,基本上你会点击一个“邀请朋友”按钮,一个朋友列表会弹出一个按钮,允许你邀请相应的用户。如何使用fb_graph从Facebook邀请朋友?

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

有没有办法用fb_graph做到这一点?

+0

像这样的事情? https://developers.facebook.com/docs/guides/games/custom-muti-friend-selector/ – CBroe

+0

是的,但理想情况下,我想使用'fb_graph'宝石 – locoboy

回答

9

你打赌。假设你有fb_graph的工作实现,你可以得到好友列表使用下面的命令(从https://github.com/nov/fb_graph):

FbGraph::User.me(fb_token).friends 

你可以用它来生成你的用户界面为你的好友列表,然后请选择朋友,像这样(来自之前的链路未测试的修饰,以及https://developers.facebook.com/docs/reference/dialogs/requests/):

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

前面的代码还可以接受以逗号分隔的UID的汇编。

我将离开你的设计和代码的用户界面,但它是可能的,使用fb_graph,肯定的。如果你决定扩大范围,这两个环节应该是坚实的黄金。

+1

这不适合我。看起来,Facebook不允许通过这种方法进行请求。所有请求都会发送给提出请求的用户。 – Paul

3

感谢您对我的宝石感兴趣。

Brad Werth's code作品现有的(=已经安装在你的应用程序)的用户,但可能不会为新用户。

在后台发送应用程序请求以避免发送垃圾邮件有很多限制。 该限制直接影响fb_graph的发送应用程序请求功能。

如果您正在开发iOS应用程序,我建议您使用FB官方iOS SDK。 https://developers.facebook.com/docs/howtos/send-requests-using-ios-sdk/

使用iOS SDK(或HTML5应用程序中的JS SDK),您的限制较少。

ps。 我不熟悉Android应用程序开发和FB官方Android SDK,但我认为他们的Android SDK也有类似的功能。

+0

我实际上是用HTML5和rails开发的。对于@iioiooioo所说的方式,我不了解宝石的限制吗?此外,通过创业板功能的最佳途径是什么? – locoboy

+0

[官方文档](https://developers.facebook.com/docs/reference/api/user/#apprequests)说*“注意:发布到/ USER_ID/apprequests的Graph API端点被认为是App to User请求应用生成的请求不会收到通知,并且与通过请求对话框“* ”从@ iioiooioo的示例代码中的参数发送的“用户到用户请求”无法收到通知并获得有限的分发。 'to'只能用作响应参数,而不是请求参数。 –

1

当然Facebook提供了一个漂亮的对话框来选择你想要发送请求的朋友。但也有一个很好的工具,内置JavaScript,通过它你有相同类型的Facebook Friends选择对话框。

JQuery Facebook Multi-Friend Selector Plugin

这个插件将使图形API调用Facebook和收集您的好友列表。这个插件的优点是它会以“延迟加载模式”加载所有的朋友列表。

1

这可能有一些帮助,我用它在我的PHP服务器上,它工作。

此代码可以帮助您发布,发送消息并向您的朋友发送请求。

head标签:

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