2012-06-20 121 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不提供直接發佈在任何人牆上。現在,您需要在牆上張貼任何內容,然後將其發佈到您朋友的牆上。 –