views:

102

answers:

5

I've been trying to get OAuth for Twitter to work on my iPhone application for the last couple of days, and I cannot for the life of me figure out why I'm getting this error. I've changed the way I've been approaching this for a while now, but still nothing. So I turn to SO to hopefully figure it out.

The tutorial is linked here. Downloading the application and running it works PERFECTLY. It doesn't work for me.

Here's the error I get -

2010-07-25 20:04:52.224 AppTest[4620:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OAToken setVerifier:]: unrecognized selector sent to instance 0x6c2acc0'

Anyone can tell me what I'm doing wrong? I'm using pretty much the same code.

EDIT: Here's the code where I use setVerifier:

- (IBAction)finishSetup:(id)sender {

        NSString *thePin = [[NSString alloc] initWithString:pinText.text];
        NSLog(@"%@", thePin);
        if([thePin length] == 7 && [[NSScanner scannerWithString:thePin] scanInt:NULL]) {

            loadingView.hidden = NO;

            [pinText resignFirstResponder];

            OAConsumer *consumer = [[OAConsumer alloc] initWithKey:consumer_key secret:consumer_secret];
            OADataFetcher *fetcher = [[OADataFetcher alloc] init];
            NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"];

            [accessToken setVerifier:pinText.text];

            NSLog(@"Using PIN %@", accessToken.verifier);
            OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url consumer:consumer token:accessToken realm:nil signatureProvider:nil];
            [request setHTTPMethod:@"POST"];

            NSLog(@"Getting access token...");

            [fetcher fetchDataWithRequest:request delegate:self didFinishSelector:@selector(accessTokenTicket:didFinishWithData:) didFailSelector:@selector(accessTokenTicket:didFailWithError:)];

        } else {

            loadingView.hidden = YES;
            error_alert = [[UIAlertView alloc]  initWithTitle:@"TestApp" message:@"The PIN you have entered is invalid. Please try again." delegate:self cancelButtonTitle:@"Cancel Login" otherButtonTitles:@"Try again", nil];
            [error_alert show];
            [error_alert release];

        }

        [thePin release];

    }
A: 

Try

[accessToken setVerifier:thePin];
BarrettJ
A: 

I think BarrettJ has it. The setVerifier argument is expecting an NSString. Since you are supplying something else, it looks for a different setVerifier that matches the signature and doesn't find it. That would result in the "Unrecognized Selector" error.

Silverlock
+1  A: 

accessToken setVerifier: expects an NSString*

thePin and pinText.text are both NSString*

Really need to show where you instantiate the accessToken variable.

aepryus
A: 

If this works, the new XCode 4 is amazing. I downloaded the ZIP file on the tutorial you linked and it appears as if OAMutableURLRequest.m has errors throughout the file thinking that NSString responds to URLEncodedString.

Try updating URLEncodedString to

stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding

Let me know if that works!

Raphael Caixeta
All XCode4 does is turn on static analysis by default. You can get the same information in the old XCode by doing a "Build And Analyze"
Kendall Helmstetter Gelner
+1  A: 

Hi iamdadude, I'm the author of the post you linked from here.

The reason you're getting this error is because you're using the wrong version of OAuthConsumer. There are several versions available, and most of them don't have the "verifier" field in OAToken and will return the error you're seeing if you try to use it. The sample project from my post contains the correct OAuthVerifier version, that's why it works.

I updated my post with a ZIP file containing only OAuthConsumer. You can use that one in your project and it will work. Of course, you can also copy only the OAuthConsumer files from my sample project and use in yours, it'll also work.

Rodrigo Sieiro