I am using the C# FaceBook API to post a status update and an image to a wall. I am using the following code:
public string PostToFaceBookPage(string appKey, string appSecret, string wallId, string postMessage, string imageUrl)
{
string id = "";
if (string.IsNullOrEmpty(imageUrl))
imageUrl = "";
var client = new Facebook.FacebookClient();
dynamic result = client.Post("oauth/access_token",
new
{
client_id = appKey,
client_secret = appSecret,
grant_type = "client_credentials",
redirect_uri = "anywhere",
scope = "publish_stream"
});
client.AccessToken = (result)["access_token"];
if (!IsId(wallId))
{
result = client.Get(wallId);
id = result["id"];
} else
{
id = wallId;
}
if (imageUrl == "")
{
result = client.Post("/" + id + "/feed", new
{
message = postMessage,
scope = "publish_stream",
privacy = "{\"value\": \"EVERYONE\"}"
});
} else
{
var uri = new Uri(imageUrl);
string imageName = Path.GetFileName(uri.LocalPath);
string mimeType = GetMimeType(Path.GetExtension(uri.LocalPath));
var media = new Facebook.FacebookMediaObject
{
FileName = imageName,
ContentType = mimeType
};
media.SetValue(GetImage(imageUrl));
result = client.Post("/" + id + "/feed", new
{
message = postMessage,
source = media,
picture = imageUrl,
scope = "publish_stream",
privacy = "{\"value\": \"EVERYONE\"}"
});
}
return "";
}
Everything is working just fine. My only problem is that my images are all posting the same exact size, regardless of the size of the actual image. Is there a way to tell FaceBook the size of the image so it doesn’t just post small thumbnails of the image?
I’m not sure if Facebook API can have these parameters as it has been a few years since I have worked with the API.
As a temporary fix however, you could try resizing the photo before uploading it to facebook.
You can use the below code from http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing