如何发布图像/照片到用户或页面的墙



我想发布一个图像或照片墙的facebook用户资料或粉丝页面。我正在使用图形api和c# .net。我正在做web请求。这是我的网页请求。

https://graph.facebook.com/pageid/photos?access_token=application_access_token&method=post&message=waterfall&source=D:Imageimage1.jpg

但是得到一个错误。"消息":

"(#324) Requires upload file"

我在网上搜索php fileupload=>true。我用c#做的。我创建了一个字节数组,并提出了多个部分的请求。但没有成功。我需要写任何东西,使网络请求。

你可以使用FacebookMediaObject:

dynamic parameters = new ExpandoObject();
parameters.message = "picture caption...";
parameters.source = new FacebookMediaObject
{
    ContentType = "image/jpeg",
    FileName = Path.GetFileName(Picture_Path)
}.SetValue(File.ReadAllBytes(Picture_Path));

下面是将图片上传到用户或facebook粉丝页面的完整功能:from my blog http://www.codicode.com/art/graph_api_post_pictures_to_a_fac.aspx

这里是javascript SDK和facebook c# SDK:

function fb_publish() {
     FB.ui(
       {
         method: 'stream.publish',
         message: 'Message here.',
         attachment: {
           name: 'Name here',
           caption: 'Caption here.',
           description: (
             'description here'
           ),
           href: 'url here'
         },
         action_links: [
           { text: 'Code', href: 'action url here' }
         ],
         user_prompt_message: 'Personal message here'
       },
       function(response) {
         if (response && response.post_id) {
           alert('Post was published.');
         } else {
           alert('Post was not published.');
         }
       }
     );  
  }

var client = new FacebookClient("my_access_token");
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://www.example.com/article.html";
parameters.picture = "http://www.example.com/article-thumbnail.jpg";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.actions = new {
    name = "View on Zombo",
    link = "http://www.zombo.com",
};
parameters.privacy = new {
    value = "ALL_FRIENDS",
};
parameters.targeting = new {
    countries = "US",
    regions = "6,53",
    locales = "6",
};
dynamic result = client.Post("me/feed", parameters);

如果有帮助,请标记为已回答:)

最新更新