Facebookのステータスを画像で送信できません。コードが見つかりましたが、例外がスローされます
The Safe handle is closed
何か足りないものがあれば教えてください。File.OpenRead(filename)が使用されたが、UnAuthorizedAccessExceptionがスローされた別の例がありました
コードは次のとおりです:
public static Stream ImageToShare
{
set
{
try
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists(ImageToShareKey))
myIsolatedStorage.DeleteFile(ImageToShareKey);
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(ImageToShareKey);
StreamResourceInfo sri = null;
Uri uri = new Uri(ImageToShareKey, UriKind.Relative);
sri = Application.GetResourceStream(uri);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(value);
//bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
}
}
catch (Exception ex)
{
AppHelper.ErrorOccured(ex);
}
}
private void postFBWithImage()
{
try
{
using (IsolatedStorageFile myFile = IsolatedStorageFile.GetUserStoreForApplication())
using (IsolatedStorageFileStream stream = myFile.OpenFile("SharePhoto", FileMode.Open, FileAccess.Read))
using (var imgFile = new FacebookMediaStream
{
ContentType = "image/jpeg",
FileName = Path.GetFileName(imgPath.Text),
}.SetValue(stream))
{
var fb = new FacebookClient(AppSettings.FacebookPIN);
fb.PostCompleted += (o, args) =>
{
if (args.Error != null)
{
notPosted(args);
return;
}
Dispatcher.BeginInvoke(() =>
{
posted();
});
};
fb.PostAsync("me/photos", new { message = ShareComments, imgFile });
}
}
catch (Exception ex)
{
AppHelper.ErrorOccured(ex);
postFBWithoutImage();
}
}