首页 文章

将图像上传到C#中的多个Facebook帐户

提问于
浏览
0

我有一个Facebook应用程序,用户可以在其中订阅 . 为了订阅,我创建了一个PHP网页,用户可以使用他的Facebook帐户信息登录,当他登录 I store the user id and the access token to my MySQL DB. 然后我将所有访问令牌作为XML文件提供给我的应用程序 .

现在,我想将状态和照片发布到订阅的用户帐户 . 但是当我想将照片上传到帐户时,我必须将照片上传到每个发布操作中的每个帐户,这种方法是无用的 .

我的发布代码如下:

public static bool PostImage(string ImageDesc, string ImagePath)
    {
        try
        {
            string accesstoken = "";

            if (ImagePath.Length < 0)
                return false;

            int progressMaxValue = Controller.participants.Descendants("participant").Count();
            int increment = 100 / progressMaxValue;

            PostImageCPanel.progressBar1.Value = 0;
            foreach (XElement xe in Controller.participants.Descendants("participant"))
            {
                try
                {
                    accesstoken = xe.Attribute("access_token").Value;

                    FacebookClient client = new FacebookClient(accesstoken); 
                    var imageStream = File.OpenRead(ImagePath);


                    dynamic res = client.Post("/me/photos", new
                    {
                        message = (ImageDesc"),
                        file = new FacebookMediaStream
                        {
                            ContentType = "image/jpg",
                            FileName = Path.GetFileName(ImagePath)
                        }.SetValue(imageStream)

                    });
                    PostImageCPanel.progressBar1.Value += increment;
                }
                catch (FacebookOAuthException ex)
                {
                    MessageBox.Show(ex);
                }                     
            }

所以,我问我是否可以 upload the photo to MySQL DB for just once and then post it to the participants Facebook accounts 而不是每次为每个帐户上传它 . Or another method to publish the photo quicker.

1 回答

  • 0

    是的,你可以,我刚刚在2天前对它进行了测试,并且使用CronJobs可以正常使用它 . 对你来说这也需要一些时间,因为每次你发布照片时,facebook都会再次上传 .

相关问题