来自 url 的 Tweetsharp SendTweetWithMedia
Tweetsharp SendTweetWithMedia from url
我正在尝试将 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。这可能吗?
最后,我只是创建了一个临时文件:
byte[] data;
using (var client = new WebClient())
{
data = client.DownloadData(thumb);
}
File.WriteAllBytes($"{Path.GetTempPath()}\xyz.jpg", data);
我能想到的最佳答案。仍然比我想要的多几行。
我正在尝试将 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。这可能吗?
最后,我只是创建了一个临时文件:
byte[] data;
using (var client = new WebClient())
{
data = client.DownloadData(thumb);
}
File.WriteAllBytes($"{Path.GetTempPath()}\xyz.jpg", data);
我能想到的最佳答案。仍然比我想要的多几行。