【问题标题】:Tweetsharp SendTweetWithMedia from url来自 url 的 Tweetsharp SendTweetWithMedia
【发布时间】: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


【解决方案1】:

最后,我只是创建了一个临时文件:

byte[] data;
using (var client = new WebClient())
{
    data = client.DownloadData(thumb);
}
File.WriteAllBytes($"{Path.GetTempPath()}\\xyz.jpg", data);

我能想到的最佳答案。不过还是比我想要的多几行。

【讨论】:

    猜你喜欢
    • 2018-01-05
    • 2013-05-02
    • 1970-01-01
    • 2012-07-01
    • 2011-10-19
    • 2013-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多