gpt4 book ai didi

c# - 您无权在群组中发帖

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

我已经用 C# 完成了一个程序,它与 Facebook 集成并通过单击向多个组发布信息

但是我现在遇到了一个问题,当有一个你没有权限发帖的组时,我无法完成发帖给其他人

这是发布功能我把它放在其他类(class)

public static bool PostImage(Frm form,string AccessToken, string Status, string ImagePath) 
{
try
{
if (form.listBox2 .SelectedItems .Count > 0)
{
string item;
foreach (int i in form. listBox2.SelectedIndices)
{
item = form.listBox2.Items[i].ToString();
groupid = item;

FacebookClient fbpost = new FacebookClient(AccessToken);
var imgstream = File.OpenRead(ImagePath);
dynamic res = fbpost.Post("/" + groupid + "/photos", new
{
message = Status,
File = new FacebookMediaStream
{
ContentType = "image/jpg",
FileName = Path.GetFileName(ImagePath)
}.SetValue(imgstream)

});
result = true;
}
}
return result;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
return false;
}
}

最佳答案

您需要在循环内放置一个 try catch block 。然后,在 catch block 中记录错误(或用它做任何你想做的事)然后继续循环:

foreach (int i in form. listBox2.SelectedIndices)
{
try
{
item = form.listBox2.Items[i].ToString();
groupid = item;

FacebookClient fbpost = new FacebookClient(AccessToken);
var imgstream = File.OpenRead(ImagePath);
dynamic res = fbpost.Post("/" + groupid + "/photos", new
{
message = Status,
File = new FacebookMediaStream
{
ContentType = "image/jpg",
FileName = Path.GetFileName(ImagePath)
}.SetValue(imgstream)

});
result = true;
}
catch(exception excp)
{
//Do something with the exception
}
}

现在我不知道你的代码是如何工作的,但这应该给你一个大概的想法。

关于c# - 您无权在群组中发帖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13617291/

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