gpt4 book ai didi

c# - 使用 TweetSharp/Hammock 将媒体上传到 Twitpic 时出现 "Headers rejected by Twitter"

转载 作者:太空狗 更新时间:2023-10-29 23:25:39 24 4
gpt4 key购买 nike

我正在尝试使用 WP7 应用程序中的 TweetSharp 和 Hammock 库将图片上传到 Twitpic。上传照片的代码是这样的:

// Clients.srv is a TweetSharp TwitterClient
RestRequest req = Clients.srv.PrepareEchoRequest();
RestClient client = new RestClient { Authority = "http://api.twitpic.com/", VersionPath = "2" };

req.AddFile("media", e.OriginalFileName, e.ChosenPhoto);
req.AddField("key", "hidden");
req.AddField("message", Tweet.Text);
req.Path = "upload.xml";
req.Method = Hammock.Web.WebMethod.Post;

client.BeginRequest(req, (RestCallback) uploadCompleted);

对代码的一些解释:这来自对 photoPickerTask 的调用,e 是包含照片名称和文件(IO.Stream 对象)的事件参数。所有这些都已验证有效。

问题是 Twitpic 的响应总是“无法验证您: header 被 Twitter 拒绝”。 TwitterClient 正常工作,OAuth token 没问题。 API key 是正确的。我不知道错误是来 self 的代码,来自 TweetSharp PrepareEchoRequest() 函数还是来自 Twitpic。谁能给我一个线索?

最佳答案

我今天遇到同样(和类似)的问题已经有好几个小时了。我终于通过将版本路径更改为 1 并将所有标记输入到请求中(如 twitpic doco 中所述)使其工作。我以为我昨天尝试了这个确切的组合,但它现在正在工作,所以祈祷 api 不会同时更新。

    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;
}

关于c# - 使用 TweetSharp/Hammock 将媒体上传到 Twitpic 时出现 "Headers rejected by Twitter",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8625821/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com