nst / STTwitter

A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1
BSD 3-Clause "New" or "Revised" License
999 stars 165 forks source link

verifyCredentialsWithSuccessBlock not returning #199

Closed boazin closed 9 years ago

boazin commented 9 years ago

So here goes - I had an old code of STTwitter not via cocoapods. Using pods now. The problem: verifyCredentialsWithSuccessBlock not returning - not success block and not errorBlock. It started with the latest version (0.2.1) so I thought it has something to do with the deprecation of the function. Reverted to 0.2.0 (with patching of the extern to get it to link) Still same thing.

When a user already logged-in in the past I'm saving it in UserDefaults and retrying with it with the following code. Any assistance on investigating will be appreciated

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *oauthAccessToken = [prefs stringForKey:@"twitterAccessToken"];
NSString *oauthAccessTokenSecret = [prefs stringForKey:@"twitterAccessTokenSecret"];
NSString *key = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"twitterKey"];
NSString *secret = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"twitterSecret"];

if (oauthAccessToken != nil) //we are logged in
{

    STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:key consumerSecret:secret oauthToken:oauthAccessToken oauthTokenSecret:oauthAccessTokenSecret];
    [twitter verifyCredentialsWithSuccessBlock:
               ^(NSString *username) {
                                //great... do stuff and login to the app

                } errorBlock:^(NSError *error) {
                    NSLog(@"error verifying credentials: %@", error);
                    [self gotoLoginScreen];
                }];
}
boazin commented 9 years ago

I updated the code, still not working. From what I was able to dig in the code: successBlock(username, userID); (ln 247 - in the success block of verifyCredentialsRemotelyWithSuccessBlock) Is getting called twice, with nil in username, and userID,

And only afterwards the GET request from twitter returns (ln 246 in STTwitterOAuth.m) and nothing is done with the result

Not sure why :(

nst commented 9 years ago

I'm confused. The following code works for me with the latest version of STTwitter. Can you double check that you're also using it? (by typing git pull)

NSString *oauthAccessToken = @"";
NSString *oauthAccessTokenSecret = @"";
NSString *key = @"";
NSString *secret = @"";

STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:key
                                                      consumerSecret:secret
                                                          oauthToken:oauthAccessToken
                                                    oauthTokenSecret:oauthAccessTokenSecret];

[twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
    NSLog(@"-- username: %@", username);
} errorBlock:^(NSError *error) {
    NSLog(@"-- error: %@", error);
}];

If it still doesn't work for you, can you please setup a minimal Xcode project, so that I'll be able to reproduce and fix the bug? Thank you for your help.

boazin commented 9 years ago

sorry for the noob question - how can I git pull if I'm using pod?

nst commented 9 years ago

Maybe you can git pull say in /tmp, replace your current STTwitter directory with the new one and run your project again.

boazin commented 9 years ago

P.S. you can get a pod from GIT by doing: pod 'STTwitter', :git => 'https://github.com/nst/STTwitter.git'

Anyway - a small project works, so it is not the code itself... I'll look for differences between the projects.

Do you think it is related to the fact that STTwitter used to be code in my project? (leftover frameworks?)

boazin commented 9 years ago

Well... after commenting out the verifyCredentialsLocallyWithSuccessBlock to see if it works and figuring out it is still gets executed I just removed all pods and podCache - reinstalled, and now everything works....

I hate Cocoapods!!!!

Well, thanks again! I believe we found a real bug in the process so it wasn't all for nothing...

nst commented 9 years ago

Glad to read that.

Don't hesitate to report any other issue you may find in the future.