Search code examples
iostwitteroauthmgtwitterengine

iOS - OAuth Twitter enginer - Failing to create tokens


In my app, i am trying to integrate posting messages to twitter. (I've generated consumer key and consumer secret in my twitter applicatin.
I'm using following code.

#pragma mark SA_OAuthTwitterEngineDelegate
- (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username {
    NSUserDefaults          *defaults = [NSUserDefaults standardUserDefaults];

    [defaults setObject: data forKey: @"authData"];
    [defaults synchronize];
}

- (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username {
    return [[NSUserDefaults standardUserDefaults] objectForKey: @"authData"];
}

- (void) twitterOAuthConnectionFailedWithData: (NSData *) data
{
    NSLog(@"Failed");
}
//=============================================================================================================================
#pragma mark SA_OAuthTwitterControllerDelegate
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
    NSLog(@"Authenicated for %@", username);
}

- (void) OAuthTwitterControllerFailed: (SA_OAuthTwitterController *) controller {
    NSLog(@"Authentication Failed!");
}

- (void) OAuthTwitterControllerCanceled: (SA_OAuthTwitterController *) controller {
    NSLog(@"Authentication Canceled.");
}

Its authorizing successfully, but the following delegate method is printing null username.

- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username

The following is the response that I'm getting:

2011-12-29 00:01:57.965 OAuthTwitterDemo[4656:207] Failed
2011-12-29 00:01:57.966 OAuthTwitterDemo[4656:207] Authenicated for (null)

Can some one suggest me what's the mistake in my code?


Solution

  • try to replace the http with https in this function

    - (SA_OAuthTwitterEngine *) initOAuthWithDelegate: (NSObject *) delegate {
    if (self = (id) [super initWithDelegate: delegate]) {
            self.requestTokenURL = [NSURL URLWithString: @"https://twitter.com/oauth/request_token"];
            self.accessTokenURL = [NSURL URLWithString: @"https://twitter.com/oauth/access_token"];
            self.authorizeURL = [NSURL URLWithString: @"https://twitter.com/oauth/authorize"];
        }
    return self;
    }