Facebook一次将多张照片上传到相册

Facebook一次将多张照片上传到相册

问题描述:

我正在开发WinService,它将文件系统中特定文件夹的照片上传到Facebook页面(要进行上传,我已经创建了Facebook应用程序并将其连接到Facebook页面),其中文件夹名称是将用于Facebook的名称专辑. 所以,首先我创建相册,一切顺利,我有了相册ID.

I am working on developing WinService which uploads photos from specific folder on file system to Facebook page (to have upload, I have made Facebook application and connected it to Facebook page), where folder name is name which will be used for Facebook album. So, first I create album, which is going fine and I have album id.

我尝试了几种将照片上传到Facebook相册的方法,但是每次为每张上传的照片生成一个弹出通知. 方式1:

I have tried several ways to upload photos to Facebook album, but each time one popup notification is generated per each uploaded photo. Way1:

FacebookClient fb = new FacebookClient(token.Trim());
//Perform upload
var imageStream = File.OpenRead(photo.Location);
fb.PostCompleted += (o, e) =>
{
    imageStream.Dispose();
    if (e.Cancelled || e.Error != null)
    {
        error = e.Error == null ? "canceled" : e.Error.Message;
    }
};
dynamic res = fb.PostTaskAsync("/" + fbAlbumID + "/photos", new
{
    message = String.Empty,
    file = new FacebookMediaStream
    {
        ContentType = "image/jpg",
        FileName = Path.GetFileName(photo.Location)
    }.SetValue(imageStream)
});
res.Wait();
var dictionary = (IDictionary<string, object>)res.Result;

way2:

dynamic result = fb.Batch(
    new FacebookBatchParameter(HttpMethod.Post, "/" + albumId + "/photos",
        new Dictionary<string, object>
        {
            {"message", "picture 1 msg"},
            {
                "pic1",
                new FacebookMediaObject {ContentType = "image/jpeg", FileName = "p4.jpg"}.SetValue(
                    File.ReadAllBytes(
                        file1path))
            }
        }),
    new FacebookBatchParameter(HttpMethod.Post, "/" + albumId + "/photos",
        new Dictionary<string, object>
        {
            {"message", "picture 1 msg"},
            {
                "pic2",
                new FacebookMediaObject {ContentType = "image/jpeg", FileName = "p4.jpg"}.SetValue(
                    File.ReadAllBytes(
                       file2path))
            }
        }
    )
);

但是对于每种方式,每张上传的照片都会为喜欢该页面的人生成弹出通知. 他们是喜欢者",将其视为垃圾邮件.

but for each way, each uploaded photo has generated popup notification for people who have liked the page. They, "likers", see this as spam.

如何实现在一张相册中上传10张照片并获得单个通知?

How to achieve to upload 10 photos in one album and to have single notification?

请指教,谢谢.

我看到任何人完成此操作(单个供稿项或单个通知)的唯一方法是使用打开图表功能.实在令人讨厌的是,基础图API并没有实现此目的的简便方法.无论您尝试批处理请求(方法2),附加照片url还是附加原始图像数据,您都将获得多个供稿项和多个通知. Twitter的API通过强制您上传多张照片并取回media_id,然后将其附加到Tweet上,来实现您想要的功能.

The only way I've seen anyone accomplish this (a single feed item, or a single notification) is by using the Open Graph functionality. It really stinks that the base graph API doesn't have an easy way to do this. Whether you try a batched request (way 2), attaching a photo url, or attaching raw image data, you'll get multiple feed items and multiple notifications. Twitter's API achieves what you want by forcing you to upload multiple photos and getting back media_ids, which you can then attach to a Tweet.

请参见 https://developers.facebook.com/docs /opengraph/using-actions/v2.2#photos .我知道设置Open Graph可能不是您想要做的,但是在发布此文章时,这似乎确实是唯一的方法. Open Graph要求您始终使用用户级访问令牌,而您正在使用页面级令牌.因此,鉴于您的要求,似乎还不可能.

See https://developers.facebook.com/docs/opengraph/using-actions/v2.2#photos. I know that setting up Open Graph may not be what you want to do, but it seems to truly be the only way at the time of this posting. Open Graph requires you to use user-level access tokens anyway, and you're using page-level tokens. So, given you're requirements, it doesn't seem to be possible yet.