开发者

Posting a tweet using OAuth from IOS app

开发者 https://www.devze.com 2023-03-09 09:21 出处:网络
I am building a twitter client for the IPhone and I\'m using OAuth to authenticate my requests to twitter,

I am building a twitter client for the IPhone and I'm using OAuth to authenticate my requests to twitter,

Right now I am able to get the home time line and even post tweets ( that do not contain any spaces or symbols) the problem starts when I try to post a tweet that contains spaces for example it gives me :{"error":"Incorrect signature","request":"\/1\/statuses\/update.json"}

For example the tweet : "ThisIsATweet" works, but the tweet : "this is a tweet" doesn't work here's my http request body code:

NSData* body =[NSString stringWithFormat:@"status=%@",[self percentageEncoding:tweet]];

[request setValue:@"application/x-www-form-开发者_C百科urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d",[body length]] forHTTPHeaderField:@"Content-Length"];

[request setHTTPBody:[body dataUsingEncoding:NSISOLatin1StringEncoding]];


Try changing the encoding to NSASCIIStringEncoding or NSUTF8StringEncoding and see if it works. I don't think you need to percent escape the message when setting it in the body. That is only needed if you add it to the URL as a param value.

[request setHTTPBody:[[NSString stringWithFormat:@"status=%@", tweet] 
    dataUsingEncoding:NSASCIIStringEncoding]];


Check your request header ! I guess you create wrong signature value! remember that your header has to be something like that:

POST http://upload.twitter.com/1/statuses/update_with_media.json

User-Agent: themattharris' HTTP Client

Host: upload.twitter.com

Accept: /

Proxy-Connection: Keep-Alive

Authorization: OAuth oauth_consumer_key="mbmuCGVFTGHZOo5zr5Sx5A", oauth_nonce="f9685243ba64308204b1c14a05950b09", oauth_signature="LX%2BcnRvzT5Rm%2BYkPzdhX6I%2Bt9oo%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1313443626", oauth_token="119476949-KQjqYB1QCSC9ZtaTI8RRDDRJdSgk8hMcT4BJMEWi", oauth_version="1.0"

Content-Length: 34411

Content-Type: multipart/form-data;
0

精彩评论

暂无评论...
验证码 换一张
取 消