Question

I'm using STTwitterto interface with Twitter in an iOS app I'm changing for someone. When I call the twitter authorization page for the first time with the following code:

- (void)newUser
{
    [[NetworkManager sharedInstance] resetTwitterAPI];
    [[[NetworkManager sharedInstance] twitterAPI] postTokenRequest:^(NSURL *url, NSString *oauthToken) {
        [[UIApplication sharedApplication] openURL:url];
    } oauthCallback:@"tweepr://twitter_access_token" errorBlock:^(NSError *error) {
        NSLog(@"Error %s", __PRETTY_FUNCTION__);
    }];
}

* Which, in turn, calls this:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    if (![[url scheme] isEqualToString:@"tweepr"]) {
        return NO;
    }

    NSDictionary *d = [self parametersDictionaryFromQueryString:[url query]];

    NSString *token = d[@"oauth_token"];
    NSString *verifier = d[@"oauth_verifier"];

    [[UserLoadingRoutine sharedRoutine] setOAuthToken:token verifier:verifier];

    return YES; 
}

* Which finally calls this:

- (void)setOAuthToken:(NSString *)token verifier:(NSString *)verifier
{
    [[[NetworkManager sharedInstance] twitterAPI] postAccessTokenRequestWithPIN:verifier successBlock:^(NSString *oauthToken, NSString *oauthTokenSecret, NSString *userID, NSString *screenName) {
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

        dict[@"nickname"] = screenName;
        dict[@"token"] = oauthToken;
        dict[@"secret"] = oauthTokenSecret;
        dict[@"user_id"] = userID;
        self.userDict = dict;
        NSMutableArray *users = [self.availableUsers mutableCopy];
        if (![users containsObject:dict]) {
            [users addObject:dict];
        }
        self.availableUsers = [users copy];
        [[NSUserDefaults standardUserDefaults] setObject:self.availableUsers forKey:@"availableUsers"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [self selectUserWithIdentifier:dict[@"nickname"]];
    } errorBlock:^(NSError *error) {
        NSLog(@"Error");
    }];
}

The twitter authorization page, the first time it comes up, has login and password fields to fill in as shown below at This Screenshot. If I bring the authorization page up again via the above code to authorize under a different user, This Screenshot appears and I need to sign out on the top. Is there a way to do this progmatically?

Was it helpful?

Solution

Append &force_login=1 to the URL string in -[STTwitterOAuth postTokenRequest:oauthCallback:errorBlock:].

Let me know if it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top