我已经用 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/