Created
July 28, 2013 02:24
-
-
Save sirvine/6097082 to your computer and use it in GitHub Desktop.
Reverse OAuth for Twitter API via Parse.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void)twitterReverseAuthResponseReceived:(NSData *)responseData | |
{ | |
if (responseData) { | |
NSString *responseStr = [[NSString alloc] | |
initWithData:responseData | |
encoding:NSUTF8StringEncoding]; | |
NSArray *parts = [responseStr componentsSeparatedByString:@"&"]; | |
if (parts.count == 4) { | |
NSString *oauthToken = [[parts objectAtIndex:0] stringByReplacingOccurrencesOfString:@"oauth_token=" withString:@""]; | |
NSString *oauthTokenSecret = [[parts objectAtIndex:1] stringByReplacingOccurrencesOfString:@"oauth_token_secret=" withString:@""]; | |
NSString *userId = [[parts objectAtIndex:2] stringByReplacingOccurrencesOfString:@"user_id=" withString:@""]; | |
NSString *screenName = [[parts objectAtIndex:3] stringByReplacingOccurrencesOfString:@"screen_name=" withString:@""]; | |
NSLog(@"userId: %@", userId); | |
NSLog(@"oauthToken: %@", oauthToken); | |
NSLog(@"oauthTokenSecret: %@", oauthTokenSecret); | |
NSLog(@"screenName: %@", screenName); | |
[PFTwitterUtils logInWithTwitterId:userId | |
screenName:screenName | |
authToken:oauthToken | |
authTokenSecret:oauthTokenSecret | |
block:^(PFUser *user, NSError *error) { | |
if (!error) { | |
if (_nativeLogInSuccessBlock) { | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
_nativeLogInSuccessBlock(user, userId, error); | |
}); | |
} | |
} | |
else { | |
[PFTwitterUtils twitterErrorOccurred:TwitterLogInErrorAuthenticationError]; | |
} | |
}]; | |
} | |
else { | |
[PFTwitterUtils twitterErrorOccurred:TwitterLogInErrorAuthenticationError]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment