问题
Does anybody sucessfuly post picture to current user's wall? This is not working, if picture argument is existing picture url post is not shown! I'm using latest FB C# SDK 5.0.8 Beta ...
var args = new Dictionary<string, object>();
args["name"] = "My App";
args["link"] = @"http://apps.facebook.com/test/";
args["caption"] = "My Caption";
args["description"] = "My Description";
args["picture"] = @"http://www.test.com/test.jpeg";
args["message"] = "My Message";
args["actions"] = "";
FbClient.PostAsync(@"/me/feed", args);
回答1:
Here is how I handled posting a photo to the Facebook User's wall. ImagePath and ImageName were string parameters that I passed into the function that contains this code.
var fbApp = new FacebookApp();
var auth = new CanvasAuthorizer(fbApp);
if (auth.IsAuthorized())
{
//Create a new dictionary of objects, with string keys
Dictionary<string, object> parameters = new Dictionary<string, object>();
string strDescription = txtDescription.Text;
//Add elements to the dictionary
if (string.IsNullOrEmpty(ImagePath) == false)
{
//There is an Image to add to the parameters
FacebookMediaObject media = new FacebookMediaObject
{
FileName = ImageName,
ContentType = "image/jpeg"
};
byte[] img = File.ReadAllBytes(ImagePath);
media.SetValue(img);
parameters.Add("source", media);
parameters.Add("message", strDescription);
try
{
dynamic result = fbApp.Api("/me/photos", parameters, HttpMethod.Post);
}
catch (Exception ex)
{
//handle error....
string strErr = ex.Message.ToString();
lblValidationMsg.Text = strErr;
}
}
}
回答2:
This is a known bug in version 5.0.8. It has been fixed in the current source and will be in the next release.
回答3:
You can use post in the user wall ("me/photos")
[TestMethod]
[DeploymentItem(@".\resources\velas_navidad.gif", @".\")]
public void Post_to_photos()
{
var ImagePath = "velas_navidad.gif";
Assert.IsTrue(File.Exists(ImagePath));
var client = new FacebookClient(token);
dynamic parameters = new ExpandoObject();
parameters.message = "Picture_Caption";
parameters.subject = "test 7979";
parameters.source = new FacebookMediaObject
{
ContentType = "image/gif",
FileName = Path.GetFileName(ImagePath)
}.SetValue(File.ReadAllBytes(ImagePath));
dynamic result = client.Post("me/photos", parameters);
Thread.Sleep(15000);
client.Delete(result.id);
}
来源:https://stackoverflow.com/questions/5500016/how-to-post-picture-on-the-wall