【发布时间】:2023-03-22 16:47:01
【问题描述】:
我正在尝试将 Tweetsharp 的 SendTweetWithMedia 与我没有在本地存储的图像一起使用,我只有一个 url。我发现的所有 SendTweetWithMedia 示例都使用本地系统上的文件。
var thumb = "http://somesite.net/imageurl";
var service = new TwitterService(key, secret);
service.AuthenticateWith(token, tokenSecret);
var req = WebRequest.Create(thumb);
using (var stream = req.GetResponse().GetResponseStream())
{
response = service.SendTweetWithMedia(new SendTweetWithMediaOptions
{
Status = tweet.Trim(),
Images = new Dictionary<string, Stream> { { fullname, stream } }
});
}
我从 SendTweetWithMedia 收到以下错误:
'System.NotSupportedException':此流不支持查找操作。
我可以从 url 下载文件并保存在本地,但我宁愿使用 url。这可能吗?
【问题讨论】:
-
您可以在接受的答案中检查读取流并将其存储到内存流中:stackoverflow.com/questions/3434007/…
-
谢谢我尝试使用内存流,它确实更进一步。但是 SendTweetWithMedia 只是超时并在大约 1 分钟后返回 null。老实说,我还不如下载 url 并保存到本地文件,因为将所有内容都转换为 MemoryStream。至少我会在其他人似乎都在使用的熟悉的基础上。
标签: c# tweetsharp