0

I try to access my user's iOS default Twitter account.

I use STTwitter library. The below code used to work fine on my device, but now it's not. The returned "oAuthToken", "oAuthTokenSecret", and "userID" are nil. but it's still working on the simulator

STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerName:nil
                                                          consumerKey:@"myConsumerKey"
                                                       consumerSecret:@"myConsumerSecret"];

[twitter postReverseOAuthTokenRequest:^(NSString *authenticationHeader) {

    STTwitterAPI *twitterAPIOS = [STTwitterAPI twitterAPIOSWithFirstAccount];

    [twitterAPIOS verifyCredentialsWithSuccessBlock:^(NSString *username) {

        [twitterAPIOS postReverseAuthAccessTokenWithAuthenticationHeader:authenticationHeader
                                                            successBlock:^(NSString *oAuthToken,
                                                                           NSString *oAuthTokenSecret,
                                                                           NSString *userID,
                                                                           NSString *screenName) {


                                                                // use the tokens...
                                                                self.oAuthToken = oAuthToken;
                                                                self.oAuthTokenSecret = oAuthTokenSecret;

                                                                if(self.oAuthToken && self.oAuthTokenSecret){
                                                                    completionHandler();

                                                                }
                                                                else{

                                                                    ACAccountStore *account = [[ACAccountStore alloc] init];
                                                                    ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

                                                                    NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];

                                                                    [account renewCredentialsForAccount:[arrayOfAccounts firstObject] completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {

                                                                             [self getUserTwitterDataFromPhoneSettingsInView:view WithCompletionHandler:completionHandler];

                                                                    }];



                                                                }

                                                            } errorBlock:^(NSError *error) {
                                                                // Error

                                                            }];

    } errorBlock:^(NSError *error) {
        // no twitter account
        // user denied access to their account(s)

    }];

} errorBlock:^(NSError *error) {
    // ...

}];
user2037296
  • 409
  • 1
  • 5
  • 13
  • STTwitter author here. I confirm that it's a bug and also that this is a regression. Let me investigate. I keep you posted. – nst May 26 '15 at 12:35

1 Answers1

0

For some reason, it turns out that the Twitter account entered in iOS Settings lacks the 'oauth_token' property and may need to be validated again. A possible fix is to go to iOS Settings and setup the account again. Now, I'll try to find a way to detect this state in STTwitter.

nst
  • 3,862
  • 1
  • 31
  • 40
  • Thanks for ur efforts=) Actually I tried to remove the account and add it again, and it didn't work. After some digging, I found out that the response has something related to my time setting, so when I change the time it works, as from where I am we did not change our clock (daylight saving)....but the weird thing is, it sometimes works even when I don't change my time. – user2037296 May 27 '15 at 23:08