【问题标题】:How to retrieve Twitter username in iphone app?如何在 iPhone 应用程序中检索 Twitter 用户名?
【发布时间】: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 实现这一点?

【问题讨论】:

    标签: iphone twitter


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

    这是从 twitter 检索用户名的代码。谢谢。

    【讨论】:

    • 但是如何在 twitter 中获取登录用户的其他信息,例如其全名 id 位置等... ??
    猜你喜欢
    • 1970-01-01
    • 2012-02-05
    • 1970-01-01
    • 2011-10-23
    • 1970-01-01
    • 2014-01-31
    • 1970-01-01
    • 2011-06-14
    • 2010-11-13
    相关资源
    最近更新 更多