【发布时间】:2018-01-05 16:47:20
【问题描述】:
我现在尝试在推特上发布几个小时的图片,但我开始怀疑它是否根本无法在 Mono 上运行?
我使用的代码是这样的:
public void SendMediaTweet(string Reply, string ImagePath)
{
if (File.Exists(ImagePath))
{
using (var stream = new FileStream(ImagePath, FileMode.Open))
{
Dictionary<string, Stream> images = new Dictionary<string, Stream> { { ImagePath, stream } };
var tweet = Service.SendTweetWithMedia(new SendTweetWithMediaOptions
{
Status = Reply,
Images = images
});
}
}
}
我已经阅读了几十个网络上的示例代码,所有这些都与我的非常相似。我错过了什么明显的东西吗?
没有上传图片,推文为空。
编辑: 正如 Yort 指出的那样,API 调用已被弃用,Tweetsharp 不支持新方法。所以我改用 TweetMoaSharp。我使用 TweetMoaSharp 解决它的方法是:
public void SendMediaTweetReply(string Reply, long StatusId, string ImagePath)
{
if (File.Exists(ImagePath))
{
using (var stream = new FileStream(ImagePath, FileMode.Open))
{
var Media = Service.UploadMedia(new UploadMediaOptions() { Media = new MediaFile() { FileName = ImagePath, Content = stream } });
List<string> MediaIds = new List<string>();
MediaIds.Add(Media.Media_Id);
var Result = Service.SendTweet(new SendTweetOptions() { Status = Reply, InReplyToStatusId = StatusId, MediaIds = MediaIds });
}
}
}
【问题讨论】:
标签: c# mono tweetsharp