lionfly
lionfly

Reputation: 479

How to get Twitter username from objective-c code?

I use the Twitter-OAuth-iPhone to authorise and send tweets, and want to show the user's twitter username on the dialog view. Although the code can get the username right, but there is always a warning:

*'SA_OAuthTwitterEngine' may not respond to '-extractUsernameFromHTTPBody:' (Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)*

The code I use to get the Twitter username are:

_engine=[[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
...
        NSString *cachedData=[[NSUserDefaults standardUserDefaults] objectForKey:@"authData"];
                NSString *twitterName=[_engine extractUsernameFromHTTPBody:cachedData];
            NSLog(@"username: %@", twitterName);

The format of extractUsernameFromHTTPBody in the SA_OAuthTwitterEngine.m is: - (NSString *) extractUsernameFromHTTPBody:(NSString *)body;

Why the warning? What is the right way for getting the Twitter username?

Upvotes: 0

Views: 1204

Answers (1)

paulbailey
paulbailey

Reputation: 5346

Are you including the header file for SA_OAuthTwitterEngine in your own code? That's what tells the compiler which methods the class has defined.

Edit

Okay, following your comment on my answer, I've looked at the source code. The method you're using is documented as private, and as such is not declared in the header file. This is causing the warning.

I think you should be using the method checkUserCredentials as defined in MGTwitterEngine.h to obtain details about the logged in user such as the username.

Upvotes: 1

Related Questions