【问题标题】:Cannot use SendTweetWithMediaOptions in windows phone无法在 windows phone 中使用 SendTweetWithMediaOptions
【发布时间】:2013-06-17 12:57:32
【问题描述】:

我在一个 Windows Phone 项目中使用 TweetSharp,无论我做什么,我都无法发布带有媒体的推文。

我收到异常 195:缺少或无效参数。

我读到这通常是导致无效数据的原因,例如我提供的流无效。

我尝试了其他方法,但没有任何效果,我得到了同样的异常......

分享代码,简化后是这样的:

MediaLibrary 库 = new MediaLibrary();

        var picture = library.Pictures[0];

        var options = new SendTweetWithMediaOptions
            {
                Images = new Dictionary<string, Stream> { { picture.Name, picture.GetImage() } },
                Status = TweetTextBox.Text,
            };


        AutentificateTwitterService().SendTweetWithMedia(options, (status, response) =>
                                    _dispatcher.BeginInvoke(() =>
                                        {
                                            DonePosting();

                                            if (response.StatusCode == HttpStatusCode.OK)
                                            {
                                                _lastPostId = status.Id;
                                            }
                                            else
                                            {
                                                MessageBox.Show(String.Format(
                                                        "There was an error sending image to Twitter{0}{1}",
                                                        Environment.NewLine,
                                                        response.Error));
                                            }
                                       })); 

我尝试与 linqtotwitter 分享并工作,但 TweetSharp 更适合我的项目。

【问题讨论】:

    标签: windows-phone tweetsharp


    【解决方案1】:

    终于在一段时间后我发现了这个问题,我确信还有其他更多与 WP 和 SendTweetWithMediaOptions 相关的问题。

    问题是,如果您以现在的方式深入到 SendTweetWithMedia 中,您将到达 TwitterService.cs,其中将调用 WithHammock,只是图像没有作为参数传递,所以它们就在那里丢失了 :)

    我确实解决了这个问题,传递参数并添加

    private void WithHammock<T>(WebMethod method, Action<T, TwitterResponse> action, string path, IDictionary<string, Stream> files, params object[] segments) where T : class
        {
            var url = ResolveUrlSegments(path, segments.ToList());
            var request = PrepareHammockQuery(url);
            request.Method = method;
            request.QueryHandling = QueryHandling.AppendToParameters;
            foreach (var file in files)
            {
                request.AddFile("media[]", file.Key, file.Value);
            }
            WithHammockImpl(request, action);
        }
    

    我会尝试看看我是否可以拉这个,以便其他人可以有这个修复。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-28
      • 1970-01-01
      • 2016-01-12
      相关资源
      最近更新 更多