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

标签 c# facebook winforms facebook-c#-sdk

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

相关文章:

ios - 在 iOS 应用程序中将图像上传到 Facebook

c# - C# 桌面应用程序中 Windows 窗体上的菜单

c# - 在我的程序 C# 中集成运行时钟

winforms - 用户无法安装单击一次应用程序

ios - Facebook SDK 原生登录报错

c# - 我如何动态引用一个程序集来寻找另一个程序集?

c# - 需要帮助手动添加到字典

c# - 如何不允许用户在文本框中输入数字

c# - 如何正确使用 LINQ2SQL DataContext 对象;每次使用重新创建都会让人头疼

ruby-on-rails - 将 Facebook 链接到现有帐户/omniauth