我正在努力與facebook圖片上傳。 我使用Facebook C#SDK 5.4.1從我的Silverligth 5應用程序(在瀏覽器中)上傳圖片。Facebook C#SDK拋出ArgumentNullException
身份驗證正在工作,我得到我的訪問令牌具有所需的權限。 (我存儲我的訪問令牌在cookie中,因爲我不希望我的Silverlight應用程序重新加載。)
這是我的代碼:
void img_LoadingCompleted(object sender, EventArgs e)
{
Dispatcher.BeginInvoke(new Action(() => { string fbcode = ReadCookie("FBCode");
ExtendedImage img = sender as ExtendedImage;
string myAppId = "MY_APPID";
string myAppSecret = "MY_SECRET";
FacebookClient fbclient = new FacebookClient(fbcode);
fbclient.PostCompleted += new EventHandler<FacebookApiEventArgs>(fbclient_PostCompleted);
FacebookMediaObject image = new FacebookMediaObject
{
ContentType = "image/jpg",
FileName = "Testpic"
};
image.SetValue(img.Pixels);
IDictionary<string, object> photoDetails = new Dictionary<string, object>
{
{"message", "Test"},
{"source", image}
};
fbclient.PostAsync("/me/photos", photoDetails);
}));
}
void fbclient_PostCompleted(object sender, FacebookApiEventArgs e)
{
if (e.Cancelled)
{
Dispatcher.BeginInvoke(new Action(() =>
{
MessageBox.Show("Cancelled: "+e.Error);
}));
}
}
唯一的例外是的PostCompleted事件拋出FacebookClient。
{System.ArgumentNullException: Der Wert darf nicht NULL sein.
Parametername: stream
bei System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen)
bei System.IO.StreamReader..ctor(Stream stream)
bei Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper, Stream responseStream, Type resultType, String& responseStr, Exception& exception, Boolean& cancelled)}
感謝您的幫助。
考慮將此標記爲答案!感謝您的跟蹤。 – 2012-02-24 03:51:03