Twitter 错误 401 - 我应该如何处理感叹号? [英] twitter error 401 - What should I do with the exclamation mark?
问题描述
我在使用 Oauth 和 twitter api ver1.1 时遇到问题.当我的应用程序将某些内容发布到另一个网站时,它会在 Twitter 上发布一条帖子.但是当帖子正文包含感叹号 ('!') 时,我收到 twitter 401 错误,即未经授权".我在谷歌上搜索,发现它可能与Oauth有关.有些人说!"必须编码为%21".我试过了,但是当我发推文!"到 twitter,我只得到了 '%21' 而不是 '!'本身.我如何编码!"正确吗?
I have a problem with Oauth and twitter api ver1.1. My app will tweet a post to twitter when post something to another site. But when the post body contains exclamation mark ('!'), I get twitter 401 error that is 'Unauthorized'. I searched on google, and found that it may related to Oauth. Some people says that the '!' must be encoded to '%21'. I tried it, but when I tweet '!' to twitter, I just got '%21' but not '!' itself. How can I encode the '!' correctly?
推荐答案
您必须使用此类别对推文进行编码
you must encode your tweet with this category
#import "NSString+URLEncoding.h"
@implementation NSString (OAURLEncodingAdditions)
- (NSString *)URLEncodedString
{
NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)self,
NULL,
CFSTR("!*'();:@&=+$,/?%#[]"),
kCFStringEncodingUTF8);
[result autorelease];
return result;
}
- (NSString*)URLDecodedString
{
NSString *result = (NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
(CFStringRef)self,
CFSTR(""),
kCFStringEncodingUTF8);
[result autorelease];
return result;
}
@end
这篇关于Twitter 错误 401 - 我应该如何处理感叹号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!