【发布时间】:2011-11-23 14:40:28
【问题描述】:
我们如何检索 iPhone 用户的 Twitter 用户名?我可以获得 Facebook 用户名。当用户登录 Facebook 时,以下代码会为我提供整个个人资料。我拆分此响应并获取用户名,即名字和姓氏。
- (void)getFacebookProfile {
NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@", [_accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDidFinishSelector:@selector(getFacebookProfileFinished:)];
[request setDelegate:self];
[request startAsynchronous];
}
#pragma mark FB Responses
- (void)getFacebookProfileFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
NSLog(@"Got Facebook Profile: %@", responseString);
NSMutableDictionary *responseJSON = [responseString JSONValue];
NSString *username;
NSString *firstName = [responseJSON objectForKey:@"first_name"];
NSString *lastName = [responseJSON objectForKey:@"last_name"];
if (firstName && lastName) {
username = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
} else {
username = @"mysterious user";
}
//[[NSUserDefaults standardUserDefaults] setObject:@"username" forKey:@"FB_LOGIN_STATUS"];
[_loginButton setTitle:username forState:UIControlStateNormal];
[self refresh];
}
#pragma mark FBFunLoginDialogDelegate
- (void)accessTokenFound:(NSString *)accessToken {
NSLog(@"Access token found: %@", accessToken);
self.accessToken = accessToken;
_loginState = LoginStateLoggedIn;
[self dismissModalViewControllerAnimated:YES];
[self getFacebookProfile];
[self refresh];
}
如何为 Twitter 实现这一点?
【问题讨论】: