TwitPic API没有正确响应 - 继续返回401

时间:2011-02-12 20:03:23

标签: c# .net twitpic

所以,我一直在努力创建这个Twitter客户端,我正在为它做图像附件,但是我无法让TwitPic API与oAuthTwitter一起使用(我用的oAuth框架)客户)。

以下是代码:

StringBuilder sb = new StringBuilder();
            filePath = filePath.Replace("\\", "/");
            sb.AppendFormat("?message={1}&media={0}&key={2}&consumer_token={3}&consumer_secret={4}&oauth_token={5}&oauth_secret={6}",
                HttpUtility.UrlEncode("@" + filePath), HttpUtility.UrlEncode(tweet), HttpUtility.UrlEncode(apiKey), HttpUtility.UrlEncode(oAuth.ConsumerKey), HttpUtility.UrlEncode(oAuth.ConsumerSecret), HttpUtility.UrlEncode(oAuth.Token), HttpUtility.UrlEncode(oAuth.TokenSecret));
            string req = sb.ToString();
            debu.Write("[DEBUG]     Request: " + req);
            string response = "hai";
            try
            {
                response = oAuth.WebRequest(oAuthTwitter.Method.POST, "http://api.twitpic.com/1/uploadAndPost.json",
                    req);
            }
            catch (Exception e) { debu.Write("[FATAL]   " + e.Message); return false; }
            debu.Write("[DEBUG]     Response: " + response);

            return true;

调试文件读取以下内容:

[2/12/2011 3:27:30 PM] [DEBUG]     Request: ?message=This+is+testing+the+image+uploader+for+TwitterAPI&media=C%3a%2fIcon.png&key=33a6804da25ac80ff3d7ba985c6e9a96&consumer_token=EPYl2jwBzUOANlRHC67Q&consumer_secret=yfOz603EbkDat1PBEq05jhvkFuYNvTPwZI1wk2uc&oauth_token=37993700-dU1ecaBlPLBFnVj4LKu6TG5yQRmmlCGr2FX97EqM&oauth_secret=4z6738kJwJaGlJgwiJ5x20prCGccpipcUdnzVpfS6U
[2/12/2011 3:27:31 PM] [FATAL]   The remote server returned an error: (400) Bad Request.

有关为什么这可能不起作用的任何建议?

1 个答案:

答案 0 :(得分:0)

您是对完整查询字符串进行URL编码。

这意味着&之类的内容会被编码为%26=会被编码为%3D。这是错误的,因为API不会将您的参数视为参数。

您应该仅对参数名称和值进行编码。