I\'m a little confused as to how I get the Twitter OAuth Token using the iOS Social Framework. Assuming I have a Facebook and Twitter account setup on iOS6, and I can get the AC
Assuming you are going to try this on >= iOS 5.0, here is an easier way to get the access token. Irrespective of whether you are using Twitter.framework or Social.framework, the way both work is by doing the request signing for you. We use either TWRequest or SLRequest to create your request. Once we are done with this, we get the NSURLRequest object from either of these.
The trick here is to look at the headers of this NSURLRequest. As we have to specify, as per OAuth standards, a few OAuth parameters and oauth_token being one of them, it should be easy to extract it out. Below is a way to get this out.
NSURLRequest * reqTemp = /* Prepare the request using either Twitter.framework or Social.framework */;
NSDictionary * dictHeaders = [reqTemp allHTTPHeaderFields];
NSString * authString = dictHeaders[@"Authorization"];
NSArray * arrayAuth = [authString componentsSeparatedByString:@","];
NSString * accessToken;
for( NSString * val in arrayAuth ) {
if( [val rangeOfString:@"oauth_token"].length > 0 ) {
accessToken =
[val stringByReplacingOccurrencesOfString:@"\""
withString:@""];
accessToken =
[accessToken stringByReplacingOccurrencesOfString:@"oauth_token="
withString:@""];
break;
}
}
May be this code can be optimized more but you get the idea. The variable accessToken will have the actual access token.