被推特拒绝的消息头"使用TweetSharp/Hammock上传媒体到Twitpic时

本文关键字:Hammock TweetSharp 媒体 Twitpic 使用 拒绝 消息 quot | 更新日期: 2023-09-27 18:18:41

我试图在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)的事件参数。流对象)。

问题是Twitpic的响应总是"Could not authenticate you: headers rejected by Twitter"。TwitterClient可以工作,OAuth令牌是正确的。API Key输入正确。我不知道错误是否来自我的代码,从TweetSharp PrepareEchoRequest()函数或从Twitpic。有人能给我点提示吗?

被推特拒绝的消息头"使用TweetSharp/Hammock上传媒体到Twitpic时

我一直有相同的(&同样的)麻烦今天太长时间了。通过将版本路径更改为1并将所有令牌输入请求(如twitpic文档中所述),我最终使其工作。我想我昨天尝试了这个确切的组合,但它现在正在工作,所以手指交叉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;
    }