IOS related solution:
1) If your device has a Twitter account (i.e. ACAccount from ACAccountStore ), the only thing you need is to connect it to SLRequest and get all the user information from the returned dictionary:
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/account/verify_credentials.json"]; NSMutableDictionary *params = [NSMutableDictionary new]; [params setObject:[Twitter sharedInstance].session.userID forKey:@"user_id"]; [params setObject:@"0" forKey:@"include_entities"]; [params setObject:@"1" forKey:@"skip_status"]; [params setObject:@"1" forKey:@"include_email"]; SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:params]; [request setAccount:twitterAccount];
2) Otherwise, you need to send OAuth user credentials (X-Auth). The easiest way is to use the TWTROAuthSigning class to retrieve OAuth parameters:
TWTROAuthSigning *oauthSigning = [[TWTROAuthSigning alloc] initWithAuthConfig: [Twitter sharedInstance].authConfig authSession:session]; NSDictionary *authHeaders = [oauthSigning OAuthEchoHeadersToVerifyCredentials];
and then send regular requests containing credentials as header fields:
NSString *oauthParameters = authHeaders[@"X-Verify-Credentials-Authorization"]; NSString *urlString = authHeaders[@"X-Auth-Service-Provider"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]]; request.allHTTPHeaderFields = @{@"Authorization":oauthParameters}; [request setHTTPMethod:@"GET"]; NSOperationQueue *queue = [[NSOperationQueue alloc]init]; [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response,NSData *data,NSError *error){ NSDictionary *twitterData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:NULL]; }];
If you support the old version of the Twitter SDK or are looking for more options, I would recommend looking at the STTwitter lib
David May 11 '15 at 6:55 2015-05-11 06:55
source share