我使用了以下代码。图片使用名称成功发布,但无法使用它发布消息/说明。请告诉我我错在哪里。它也没有任何例外。
private void SharePhoto(string _accessToken, string p)
{
var fb = new FacebookClient(_accessToken);
fb.PostCompleted += (o, args) =>
{
if (args.Error != null)
{
if (args.Error.Message.StartsWith("(OAuthException - #190)"))
{
Dispatcher.BeginInvoke(() =>
{ MessageBox.Show("Message Expired"); });
}
else
{
Dispatcher.BeginInvoke(() =>
{ MessageBox.Show(args.Error.Message, "Error", MessageBoxButton.OK); });
}
return;
}
else
{
Dispatcher.BeginInvoke(() =>
{ MessageBox.Show("Image Posted"); });
}
};
var fbupload = new FacebookMediaObject
{
FileName = "facebook.jpg",
ContentType = "image/jpeg"
};
StreamResourceInfo sri =Application.GetResourceStream(new Uri("facebook.jpg",UriKind.Relative));
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(sri.Stream);
var loadedImage = new WriteableBitmap(bitmap);
using (MemoryStream ms = new MemoryStream())
{
loadedImage.SaveJpeg(ms, loadedImage.PixelWidth, loadedImage.PixelHeight, 0, 95);
ms.Seek(0, 0);
byte[] data = new byte[ms.Length];
ms.Read(data, 0, data.Length);
ms.Close();
fbupload.SetValue(data);
}
var parameters = new Dictionary<string, object>();
parameters["message"] = txtMessage.Text;
parameters["description"] = "first ever one";
parameters["name"] = "My FB Pic";
parameters["picture"]=fbupload;
parameters["link"] = new Uri(@"http://www.anyxyz.com", UriKind.Absolute);
fb.PostAsync(@"me/photos", parameters);
}
我使用扩展权限:
private const string extendedPermissions = "user_about_me,read_stream,publish_stream";
非常感谢任何帮助。