2012-06-20 88 views
1

我正在使用Facebook API开发一个网站,使用Facebook API并获取登录用户的好友列表。我将这个列表绑定在Datalist中,并带有复选框,朋友图片,姓名和用户ID。在我的网站使用Facebook API邀请Facebook朋友

当我检查一些复选框并点击一个按钮时,我想发送某种邀请给检查的朋友。我想通过私人消息,通知或任何其他解决方案发送邀请(但用户墙上的而不是)。这可能吗?

我已经检查了所有帖子,它们已经在Stackoverflow中。 而且还检查了这一个http://www.fbrell.com/xfbml/fb:server-fbml-multi-friend-selector

回答

1

你要找的是所谓"App-generated Requests"。这些是从你的应用程序中,而无需用户看到或在requests dialog.

行事下面的代码是从Facebook的资料为准发送的请求 - https://developers.facebook.com/docs/channels/#requests

<?php 

    $app_id = YOUR_APP_ID; 
    $app_secret = YOUR_APP_SECRET; 

    $token_url = "https://graph.facebook.com/oauth/access_token?" . 
    "client_id=" . $app_id . 
    "&client_secret=" . $app_secret . 
    "&grant_type=client_credentials"; 

    $app_access_token = file_get_contents($token_url); 

    $user_id = THE_CURRENT_USER_ID; 

    $apprequest_url ="https://graph.facebook.com/" . 
    $user_id . 
    "/apprequests?message='INSERT_UT8_STRING_MSG'" . 
    "&data='INSERT_STRING_DATA'&" . 
    $app_access_token . "&method=post"; 

    $result = file_get_contents($apprequest_url); 
    echo("App Request sent?", $result); 
?> 

一旦发送出去,新用户收到的请求在您的应用程序的书签上作为计数器 可见,并且还会将计数器 递增到相应的仪表板。

该代码是在PHP中,但它使用非常通用的file_get_contents()方法。您可以使用任何能够发出HTTP请求的语言来使用此逻辑。

+1

谢谢LIX先生,但它是用于帆布和移动应用,而不是网站。你可以告诉我任何方式,我们怎么能在用户的朋友墙上发布信息,以及它需要哪个权限? 再次感谢! :) –

+0

您可以使用画布设置应用程序,只需将画布重定向回您的网站即可。你必须有一个画布网址才能使用请求...关于在人墙上张贴,你需要'publish_stream'许可...... – Lix

0

此代码将贴在你的朋友的墙,无论你想发布:

   for (Int32 i = 1; i < DLFbFriend.Items.Count; i++){ 

       CheckBox Chkbox =(CheckBox)DLFbFriend.Items[i].FindControl("chkUserID"); 
       if (Chkbox.Checked) 
       { 
        HiddenField hdfUserId = (HiddenField)DLFbFriend.Items[i].FindControl("hdfUserID"); 
        string d = hdfUserId.Value;//friend's facebook generated id,whom you want to invite 
        String link = "what ever you want to post"; 
        string url1 = "https://graph.facebook.com/" + d + "/feed?access_token=" + Request.QueryString["access_token"] + "&link=" + link + "&from=" + Session["Pinny_USER"].ToString().Split('~')[0] + "&name=Register with Pinny&message=Your friend invites you&picture=http://168.144.124.15/images/logoPinny.jpeg"; 
        HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1); 
        request1.Method = "POST"; 
        // execute the request 
        HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse(); 

        // we will read data via the response stream 
        System.IO.Stream ReceiveStream1 = response1.GetResponseStream(); 
        StreamReader readStream1 = new StreamReader(ReceiveStream1); 
        string json1 = readStream1.ReadToEnd(); 
        countinvited += 1; 
       } 
      } 
+0

现在Facebook不提供直接发布在任何人墙上。现在,您需要在墙上张贴任何内容,然后将其发布到您朋友的墙上。 –