【问题标题】:Invite facebook friends in my website using facebook API使用 facebook API 在我的网站中邀请 facebook 朋友
【发布时间】:2012-06-20 14:40:58
【问题描述】:

我正在用 C# 开发一个网站,使用 Facebook API 并登录用户的朋友列表。我将此列表与复选框、朋友图片、姓名和用户 ID 绑定在 Datalist 中。

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

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

【问题讨论】:

    标签: asp.net c#-4.0 facebook-graph-api


    【解决方案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 请求的语言一起使用。

    【讨论】:

    • 感谢 Lix 先生,但它用于画布和移动应用程序,而不是用于网站。你能告诉我,我们如何在用户的朋友墙上发帖以及需要哪些权限?再次感谢!! :)
    • 您可以使用画布设置应用程序,该画布只需重定向回您的网站。您必须有一个画布 URL 才能使用请求...关于在人民墙上发帖,您需要 publish_stream 权限...
    【解决方案2】:

    此代码将发布在您朋友的墙上,无论您想发布什么:

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

    【讨论】:

    • 现在 facebook 不提供在任何人墙上的直接发布。现在你需要在你的墙上张贴任何东西,然后你可以把它贴在你朋友的墙上。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多