2014-03-19 76 views
0

我知道如何閱讀fb的收件箱,但不知道如何使用c#回覆。如何回覆使用c#/ asp.net的facebook收件箱消息

protected void Button4_Click(object sender, EventArgs e) 
{ 
    var fb = new FacebookClient(lblToken.Text); 
    var query = string.Format(@"SELECT message_id, author_id, body, created_time FROM message WHERE thread_id IN (SELECT thread_id FROM thread WHERE folder_id = 0)"); 
    dynamic parameters = new ExpandoObject(); 
    parameters.q = query; 
    dynamic results = fb.Get("/fql", parameters);  
    List<MyMessage> q = JsonConvert.DeserializeObject<List<MyMessage>>(results.data.ToString()); 
    GridView4.DataSource = q; 
    GridView4.DataBind();  
} 

回答

0

我得到了解決方案如何回覆Facebook的私人信息。但這隻適用於Facebook粉絲頁面。

首先它需要有頁面的訪問令牌。然後點擊按鈕,把這段代碼:

var fb = new FacebookClient(lblToken.Text); 
    var query = string.Format(@"SELECT body,message_id,sender,participants, html_body, attachments FROM unified_message WHERE thread_id = 0 ");// and viewer_id = " + orligPage);//SELECT message_count FROM thread WHERE folder_id = 0 
    dynamic parameters = new ExpandoObject(); 
    parameters.q = query; 
    dynamic results = fb.Get("551183598322481/conversations");//678999761//551183598322481 
    List<Refer.MyPage> q = JsonConvert.DeserializeObject<List<Refer.MyPage>>(results.data.ToString()); 
    gvPageInbox.DataSource = q; 
    gvPageInbox.DataBind(); 

我需要這個gridview來檢索conversation_id。所以我們可以從c#頁面查看facebook上的conversation_id和消息。

這需要兩個文本框和一個按鈕後,從asp.net頁面回覆的談話: 代碼前端:

Body :&nbsp; 
    <asp:TextBox ID="txtBodyMsg" runat="server" Width="420px"></asp:TextBox> 
     &nbsp;&nbsp;&nbsp;&nbsp; which Conversation:&nbsp;<asp:TextBox ID="txtConversationID" 
      runat="server" Width="285px"></asp:TextBox> 

然後在點擊按鈕把這個代碼:

protected void Button7_Click(object sender, EventArgs e) 
{ 

    var fb = new FacebookClient(lblToken.Text); 
    var to = new Dictionary<string, object> 
           { 
            {"id", "100000147534139"} 
           }; 

    var jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); 
    var jsonTo = jsonSerializer.Serialize(to); 
    var commentDicitonay = new Dictionary<string, object> 
           { 
            {"id", txtConversationID.Text}, //plese enter full conversation ID// eg: t_mid.1395805167639:9ac20dbffcd33a5d13 
            {"message" , txtBodyMsg.Text}, 
            {"to" , txtMsgTo.Text} 
           }; 
    fb.Post("messages/", commentDicitonay); 
    lblMessage.ForeColor = System.Drawing.Color.Red; 
    lblMessage.Text = "Messages Replied!"; 
} 
相關問題