0

所以,我一直在尝试制作这个 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.

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

4

1 回答 1

0

您正在对完整的查询字符串进行 URL 编码。

这意味着诸如&被编码为%26=as之类的东西%3D。这是错误的,因为您的参数不会被 API 视为参数。

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

于 2011-02-12T20:06:02.927 回答