我知道如何在fb上阅读收件箱,但不知道如何使用c#回复。
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 :(得分: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#page上查看facebook上的conversation_id和消息。
之后需要两个文本框和一个按钮来回复asp.net页面中的对话: 前端代码:
Body :
<asp:TextBox ID="txtBodyMsg" runat="server" Width="420px"></asp:TextBox>
which Conversation: <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!";
}