gpt4 book ai didi

c# - 如何使用 Facebook C# SDK 读取/发送私有(private)消息?

转载 作者:太空宇宙 更新时间:2023-11-03 19:26:49 24 4
gpt4 key购买 nike

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

最佳答案

要访问消息(聊天消息),您必须拥有 read_mailbox 扩展权限(我认为)并且喜欢:

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

您可以尝试 https://developers.facebook.com/tools/explorer

阅读更多:

Inbox Notifications , Message Info

变化:coming soon changes

希望对您有所帮助 ;)

关于c# - 如何使用 Facebook C# SDK 读取/发送私有(private)消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8016939/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com