views:

118

answers:

2

Hello,

I am working on a test app to help me better understand the way oAuth works with the Twitter API for a bigger app I would like to write, however I am experiencing an issue posting messages to the API after successfully getting an access token.

I am using the OAuthConsumer framework as it seemed to be the easiest way to work through the yo-yo that is oAuth...

My code is further down, along with the console log, and I have included a link to a ZIP file of the XCode project.

http://dropbox.unknowndomain.co.uk/oAuth-Test-App.zip

Error:

Error Domain=NSURLErrorDomain Code=-1012 UserInfo=0x10029a100 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" Underlying Error=(Error Domain=kCFErrorDomainCFNetwork Code=-1012 UserInfo=0x100296310 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)")

This is the error I get back when it calls the API to send a tweet, now bear in mind that I have used this same exact code to call unprotected resources on the API with no problem and got a response just fine, however when sending a tweet I get an error which on closer investigation I got some hints of an error 401 which suggests the previous key is not valid, but I cannot imagine why.

I have been sitting on this for a week now completely stumped, so help regardless of experience might just uncover a hidden problem, that said a few people seem to have had this -1012 error on the Google Code page but there are no answers there. `

Console Log:

2010-07-10 23:15:08.909 oAuth Test App[1732:a0f] Request Token: oauth_token=***&oauth_token_secret=***&oauth_callback_confirmed=true

2010-07-10 23:15:21.131 oAuth Test App[1732:a0f] Access Token: oauth_token=***&oauth_token_secret=***&user_id=***&screen_name=***

2010-07-10 23:15:29.439 oAuth Test App[1732:a0f] EPIC FAIL!

2010-07-10 23:15:29.440 oAuth Test App[1732:a0f] Access Token: <OAToken: 0x125408160>
2010-07-10 23:15:29.440 oAuth Test App[1732:a0f] Key: ***
2010-07-10 23:15:29.440 oAuth Test App[1732:a0f] Secret: ***

2010-07-10 23:15:29.440 oAuth Test App[1732:a0f] Service Ticket: <OAServiceTicket: 0x100296050>

2010-07-10 23:15:29.457 oAuth Test App[1732:a0f] Data: Error Domain=NSURLErrorDomain Code=-1012 UserInfo=0x10029a100 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" Underlying Error=(Error Domain=kCFErrorDomainCFNetwork Code=-1012 UserInfo=0x100296310 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)")

Thanks for your help!

+1  A: 

I found that I was getting this error because I was using OAPlaintextSignatureProvider as the signatureProvider when creating my OAMutableURLRequest. Passing nil instead worked fine.

skorulis
A: 

In fact while @skorulis is correct there is an issue with the signature provider, in terms of the Twitter API it seems that some parts of the API are happy with a Plain Text signature while others require HMAC-SHA1...

Using this as the signatureProvider: will solve any issues including the above issue...

[[[OAHMAC_SHA1SignatureProvider alloc] init] autorelease]

Also there was a 2nd issue where the content downloaded from the server was not always complete, or was appended with junk text...

The lovely people on IRC were able to help solve this, in the case examples it uses stringWithCString: which is depreciated and the alternative...

stringWithCString:encoding: was also the wrong thing to use as it looks for a null character to end, luckily my app wasn't crashing because of this but it was continuing to fetch memory until it found a character of this type, often for quite a while...

Instead use:

[[[NSString alloc] initWithData:data encoding: NSUTF8StringEncoding] autorelease]
unknowndomain
BTW I had found the solution before @skorulis but didn't see the commenting, sorry for the late post.
unknowndomain