无法在Windows Phone上使用TweetSharp 2.3.0与媒体一起推特
本文关键字:媒体 一起 TweetSharp Windows Phone | 更新日期: 2023-09-27 18:21:48
我对SendTweetWithMedia()有问题。以下是我如何实现
var service = new TwitterService(TwitterSettings.ConsumerKey, TwitterSettings.ConsumerSecret);
service.AuthenticateWith(twitterAccess.AccessToken, twitterAccess.AccessTokenSecret);
string status = string.IsNullOrEmpty(message) ? " " : message;
var memoryStream = new MemoryStream();
bitmap.SaveJpeg(memoryStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
memoryStream.Position = 0;
var options = new SendTweetWithMediaOptions
{
Status = status,
Images = new Dictionary<string, Stream> {{"picture", memoryStream}}
};
service.SendTweetWithMedia(options, (responseStatus, response) => Dispatcher.BeginInvoke(() =>
{
memoryStream.Close();
memoryStream.Dispose();
if (response.StatusCode == HttpStatusCode.OK)
{
UiHelper.ShowToastPrompt(AppResources.TwitterToastPrompt);
}
else if (response.StatusCode == HttpStatusCode.Unauthorized)
{
NavigationService.Navigate(new Uri("/TwitterLoginPage.xaml", UriKind.Relative));
}
else
{
MessageBox.Show(response.StatusDescription, AppResources.ErrorMessageBoxCaption, MessageBoxButton.OK);
}
}));
但信息框中显示"禁止"。
甚至我也试着从SendTweetWithMediaOptions中删除图片,但无济于事。
有人能帮忙吗?谢谢
最后,我可以使用TweetSharp+Hammock将照片上传到Twitter,代码为
TwitterService service = new TwitterService(consumerKey, consumerSecret);
service.AuthenticateWith(accessToken, accessTokenSecret);
if (thumbnail != null) // an image post - go through twitpic
{
MemoryStream ms = new MemoryStream();
thumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Seek(0, SeekOrigin.Begin);
// Prepare an OAuth Echo request to TwitPic
RestRequest request = service.PrepareEchoRequest();
request.Path = "uploadAndPost.xml";
request.AddField("key", twitpicApiKey);
request.AddField("consumer_token", consumerKey);
request.AddField("consumer_secret", consumerSecret);
request.AddField("oauth_token", accessToken);
request.AddField("oauth_secret", accessTokenSecret);
request.AddField("message", "Failwhale!");
request.AddFile("media", "failwhale" + Environment.TickCount.ToString(), ms, "image/jpeg");
// Post photo to TwitPic with Hammock
RestClient client = new RestClient { Authority = "http://api.twitpic.com/", VersionPath = "1" };
RestResponse response = client.Request(request);
return response.Content;
}
将VersionPath的值设置为1非常重要。我以前用过2,但没用。