Reputation: 109
I want to post an image or photo to wall of facebook user profile or fan page.I am using graph api and C#.net.I am doing with web request.Here is my web request.
https://graph.facebook.com/pageid/photos?access_token=application_access_token&method=post&message=waterfall&source=D:\Image\image1.jpg
But getting an error. "message":
"(#324) Requires upload file"
I searched on the net for php fileupload=>true.I am doing in C#.I created a byte array and made a request in multiple part.But did not worked out.Does I need to write any thing in making web request.Let me know.
Upvotes: 2
Views: 4893
Reputation: 11515
you can use the 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));
here's the full function to upload a picture to a user or to a facebook fan page: from my blog http://www.codicode.com/art/graph_api_post_pictures_to_a_fac.aspx
Upvotes: 5
Reputation: 1296
here is with javascript sdk and 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.');
}
}
);
}
and
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);
and would you please mark it as answered if it helps :)
Upvotes: 4