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

时间:2011-07-29 05:07:09

标签: c# facebook facebook-graph-api facebook-c#-sdk

我想将图片或照片发布到Facebook用户个人资料或粉丝页面的墙上。我正在使用图形api和C#.net。我正在处理网络请求。这是我的网络请求。

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

但是收到错误。 “消息”:

"(#324) Requires upload file"

我在网上搜索了php fileupload => true。我在C#中做。我创建了一个字节数组,并在多个部分发出了请求。但是没有解决。我需要写任何东西制作网络请求。让我知道。

2 个答案:

答案 0 :(得分:5)

您可以使用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粉丝页面的完整功能: 来自我的博客 http://www.codicode.com/art/graph_api_post_pictures_to_a_fac.aspx

答案 1 :(得分:4)

这里是javascript sdk和facebbok 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);

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