C#中的Facebook上传问题
本文关键字:问题 Facebook 中的 | 更新日期: 2023-09-27 17:57:54
当我尝试使用facebook API
将images/videos
上载到facebook
时。facebook API
给出如下所示的异常
"One or more errors occurred.System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Security._SslStream.StartWriting(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ProcessWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.ConnectStream.InternalWrite(Boolean async, Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at Facebook.FacebookClient.<>c__DisplayClass6.<ApiAsync>b__4(Object o, OpenWriteCompletedEventArgs e) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)"
使用的代码是:
FacebookMediaStream facebookMediaObject = new FacebookMediaStream { FileName = fileName, ContentType = mimeType };
Stream stream = new MemoryStream(bytearray);
facebookMediaObject.SetValue(stream);
var postInfo = new Dictionary<string, object>();
postInfo.Add("message", fileName);
postInfo.Add("image", facebookMediaObject);
var tasktest = _fbClient.PostTaskAsync(String.Format("/{0}/photos", parentFolderID), postInfo);
tasktest.Wait();
facebookMediaObject.Dispose();
stream.Dispose();
查看此Prabir的博客
var fb = new FacebookClient("access_token");
dynamic parameters = new ExpandoObject();
parameters.source = new FacebookMediaObject { ContentType = "video/3gpp", FileName = "video.3gp" }.SetValue(File.ReadAllBytes(@"c:'video.3gp"));
parameters.title = "video title";
parameters.description = "video description";
dynamic result = fb.Post("/me/videos", parameters);
Console.WriteLine(result);