2011-11-23 540 views
0

我們如何檢索iPhone用戶的Twitter用戶名?我可以得到Facebook的用戶名。當用戶登錄到Facebook時,以下代碼給我提供了整個配置文件。我分開這個迴應並得到用戶名,即名和姓。如何檢索iphone應用程序中的Twitter用戶名?

- (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?

回答

0
#pragma mark SA_OAuthTwitterControllerDelegate 
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username { 
    NSLog(@"Authenicated for %@", username); 
    [_btnTwitter setTitle:username forState:UIControlStateNormal]; 
} 

這是從twitter.Thanks獲取用戶名的代碼。

+0

但如何獲取登錄用戶的其他信息,如其全名ID位置等? – Abhishek

相關問題