如何使用Facebook C#SDK阅读/发送私人消息?

如何使用Facebook C#SDK阅读/发送私人消息?,c#,.net,windows-phone-7,facebook-c#-sdk,C#,.net,Windows Phone 7,Facebook C# Sdk,我从Facebook的C#SDK开始。如何处理官方SDK文档中的消息?我如何阅读和发送信息?有教程吗?这是用来发送消息的 使用Facebook C#SDK(http://facebooksdk.codeplex.com) var-app=新的facebook应用(“访问令牌”); var参数=新字典(); 参数[“消息”]=“这是一条测试消息”; app.Api(“/me”,参数,HttpMethod.Post); 这将在当前用户的墙上发布消息。您还可以使用该SDK发布图像。测试中有关于如何做

我从Facebook的C#SDK开始。如何处理官方SDK文档中的消息?我如何阅读和发送信息?有教程吗?

这是用来发送消息的

使用Facebook C#SDK(http://facebooksdk.codeplex.com)

var-app=新的facebook应用(“访问令牌”);
var参数=新字典();
参数[“消息”]=“这是一条测试消息”;
app.Api(“/me”,参数,HttpMethod.Post);

这将在当前用户的墙上发布消息。您还可以使用该SDK发布图像。测试中有关于如何做到这一点的样本。请注意,如果您的意思是希望向他们发送私人消息,而不是在他们的墙上张贴,则这是不可能的。Facebook不允许应用程序直接向用户发送消息。

这是用于发送消息的

使用Facebook C#SDK(http://facebooksdk.codeplex.com)

var-app=新的facebook应用(“访问令牌”);
var参数=新字典();
参数[“消息”]=“这是一条测试消息”;
app.Api(“/me”,参数,HttpMethod.Post);
这将在当前用户的墙上发布消息。您还可以使用该SDK发布图像。测试中有关于如何做到这一点的样本。请注意,如果您的意思是希望向他们发送私人消息,而不是在他们的墙上张贴,则这是不可能的。Facebook不允许应用程序直接向用户发送消息。

要访问消息(聊天消息),您必须拥有read_邮箱扩展权限(我认为),并执行以下操作:

string facebookToken = "your facebook token here";
var client = new FacebookClient(facebookToken);

dynamic result = client.Get("me/inbox", null);

foreach (dynamic item in result.inbox.data)
{
    //item is a conversation
    //the latest updated conversations come first so
    //im just gona grab the first conversation with unreaded / unseen messages

    if (item.unread > 0 || item.unseen > 0)
    {
        string conversationID = item.id;
        string otherPerson = item.to.data[1].name;//the item.to.data[0] its myself

        //you can access the messages of the conversation like
        //by default it will return the last 25 messages, u can get more, by making a call too
        //"https://graph.facebook.com/{0}/comments?limit={1}" like:
        //dynamic result = client.Get(string.Format("{0}/comments?limit={1}",conversationID, 100), null);
        foreach (dynamic message in item.comments.data)
        {
            //Do want you want with the messages
            string id = message.id;
            string fromName = message.from.name;
            string fromID = message.from.id;
            string text = message.message;
            string createdDate = message.created_time;
        }

        //To send a message in this conversation, just
        dynamic parameters = new ExpandoObject();
        parameters.message = "A message from code!";
        client.Post(string.Format("{0}/comments", conversationID), parameters);
        //or
        //client.Post(string.Format("{0}/comments", conversationID), new Dictionary<string, object> { { "message", "A message from code!" } });

        //NOTE!! - The application must be on white list for you te be able to post a message 
        // read - https://developers.facebook.com/docs/ApplicationSecurity/

        break;
    }
}
string facebook-token=“您的facebook-token在此”;
var client=新的FacebookClient(facebookToken);
动态结果=client.Get(“我/收件箱”,null);
foreach(result.inbox.data中的动态项)
{
//项目是一个对话
//最新更新的对话排在第一位
//我只是想用未读/未看的信息抓住第一个对话
如果(item.unread>0 | | item.unseen>0)
{
字符串conversationID=item.id;
字符串otherPerson=item.to.data[1].name;//item.to.data[0]是自己的
//您可以访问对话的消息,如
//默认情况下,它将返回最后25条消息,你也可以通过打电话获得更多消息
//"https://graph.facebook.com/{0}/comments?limit={1}类似:
//动态结果=client.Get(string.Format(“{0}/comments?limit={1}”,conversationID,100),null);
foreach(item.comments.data中的动态消息)
{
//你想用这些信息吗
字符串id=message.id;
字符串fromName=message.from.name;
字符串fromID=message.from.id;
字符串文本=message.message;
字符串createdDate=message.created\u time;
}
//要在此对话中发送消息,请
动态参数=新的ExpandooObject();
parameters.message=“来自代码的消息!”;
client.Post(string.Format(“{0}/comments”,conversationID),参数);
//或
//client.Post(string.Format(“{0}/comments”,conversationID),新字典{{“message”,“代码中的消息!”});
//注意!!-应用程序必须在白名单上才能发布消息
//读-https://developers.facebook.com/docs/ApplicationSecurity/
打破
}
}
你可以试试看

请阅读以下内容:

,,

变化:

希望有帮助;)

要访问邮件(聊天邮件),您必须拥有read_邮箱扩展权限(我认为),并执行以下操作:

string facebookToken = "your facebook token here";
var client = new FacebookClient(facebookToken);

dynamic result = client.Get("me/inbox", null);

foreach (dynamic item in result.inbox.data)
{
    //item is a conversation
    //the latest updated conversations come first so
    //im just gona grab the first conversation with unreaded / unseen messages

    if (item.unread > 0 || item.unseen > 0)
    {
        string conversationID = item.id;
        string otherPerson = item.to.data[1].name;//the item.to.data[0] its myself

        //you can access the messages of the conversation like
        //by default it will return the last 25 messages, u can get more, by making a call too
        //"https://graph.facebook.com/{0}/comments?limit={1}" like:
        //dynamic result = client.Get(string.Format("{0}/comments?limit={1}",conversationID, 100), null);
        foreach (dynamic message in item.comments.data)
        {
            //Do want you want with the messages
            string id = message.id;
            string fromName = message.from.name;
            string fromID = message.from.id;
            string text = message.message;
            string createdDate = message.created_time;
        }

        //To send a message in this conversation, just
        dynamic parameters = new ExpandoObject();
        parameters.message = "A message from code!";
        client.Post(string.Format("{0}/comments", conversationID), parameters);
        //or
        //client.Post(string.Format("{0}/comments", conversationID), new Dictionary<string, object> { { "message", "A message from code!" } });

        //NOTE!! - The application must be on white list for you te be able to post a message 
        // read - https://developers.facebook.com/docs/ApplicationSecurity/

        break;
    }
}
string facebook-token=“您的facebook-token在此”;
var client=新的FacebookClient(facebookToken);
动态结果=client.Get(“我/收件箱”,null);
foreach(result.inbox.data中的动态项)
{
//项目是一个对话
//最新更新的对话排在第一位
//我只是想用未读/未看的信息抓住第一个对话
如果(item.unread>0 | | item.unseen>0)
{
字符串conversationID=item.id;
字符串otherPerson=item.to.data[1].name;//item.to.data[0]是自己的
//您可以访问对话的消息,如
//默认情况下,它将返回最后25条消息,你也可以通过打电话获得更多消息
//"https://graph.facebook.com/{0}/comments?limit={1}类似:
//动态结果=client.Get(string.Format(“{0}/comments?limit={1}”,conversationID,100),null);
foreach(item.comments.data中的动态消息)
{
//你想用这些信息吗
字符串id=message.id;
字符串fromName=message.from.name;
字符串fromID=message.from.id;
字符串文本=message.message;
字符串createdDate=message.created\u time;
}
//要在此对话中发送消息,请
动态参数=新的ExpandooObject();
parameters.message=“来自代码的消息!”;
client.Post(string.Format(“{0}/comments”,conversationID),参数);
//或
//client.Post(string.Format(“{0}/comments”,conversationID),新字典{{“message”,“代码中的消息!”});
//注意!!-应用程序必须在白名单上才能发布消息
//读-https://developers.facebook.com/docs/ApplicationSecurity/
打破
}
}
你可以试试看

请阅读以下内容:

,,

变化:


希望有帮助;)

Facebook不允许SDK发送私人消息以防止垃圾邮件发送者误用

Facebook不允许SDK发送私人消息以防止垃圾邮件发送者误用

以下是如何使用c#,asp.net显示收件箱:

protectedvoid按钮4\u单击(对象发送者,事件参数e)
{
var fb=新的FacebookClient(lblToken.Text);
var query=string.Format(@“从线程id所在的消息中选择消息id、作者id、正文、创建时间”
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();

}