2

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?

Satyam
  • 15,493
  • 31
  • 131
  • 244

3 Answers3

5

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;
}
musefan
  • 47,875
  • 21
  • 135
  • 185
John Hanna
  • 94
  • 5
  • This didn't work for me, seems to be failing consistently only on the iPad, although does occur on iPhone rarely. Please check my post: http://stackoverflow.com/questions/9396323/twitter-request-token-invalid-on-ios – Daniel Feb 22 '12 at 14:25
0

Yep..!it works for me :) , the url with http will work without problem in ios ios 4.* but you have to replace to https to work with ios 5.1 version.

Ranganatha G V
  • 415
  • 5
  • 12
0

The problem is not with the URL's for request, authorize etc. There's a change in the twitter or iOS itself which is causing issues. For iOS 4, without any changes in twitter engine, its work perfect. But on iOS5, we have to use twitter framework. This solved my problem.

Satyam
  • 15,493
  • 31
  • 131
  • 244