在iOS 6中获取真正的推特用户名 [英] Get the real twitter username in iOS 6

查看:416
本文介绍了在iOS 6中获取真正的推特用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到应用用户的Twitter手柄的用户名,因此使用此代码:

I wanted to find the username of the app user's twitter handle, so used this code:

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
    if (granted) {
        NSArray *accounts = [accountStore accountsWithAccountType:accountType];

然后从返回的每个ACAccounts获取用户名属性。我发现如果你改变你的推特用户名,iOS仍然可以使用你的新用户名,但保留你的旧用户名在其记录中,所以返回用户名属性实际上会返回你的旧用户名,然后你无法显示或用来匹配反对任何事情。

And then got the username property from each of the ACAccounts returned. I discovered that if you change your twitter username though, iOS still works with your new username, but keeps your old username in it's records, so returning the username property actually returns your old username, which you can't then display or use to match against anything.

您可以通过以下方式获取用户ID:

You can get the user ID, by doing this:

NSDictionary *tempDict = [[NSMutableDictionary alloc] initWithDictionary:
                                                              [twitterAccount dictionaryWithValuesForKeys:[NSArray arrayWithObject:@"properties"]]];
NSString *tempUserID = [[tempDict objectForKey:@"properties"] objectForKey:@"user_id"];

我想知道如何使用该用户名来查找他们的实际用户名?

I was wondering how I could use that User ID to find out their actual username?

推荐答案

在这里你去:twitterAccout.username应该返回实际的用户名...没有经过测试,但我确信它几乎可以肯定它会起作用!

Here you go: twitterAccout.username should return the actual username... Not tested but I am sure almost sure it will work !

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
    if(granted) {
        NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

        if ([accountsArray count] > 0) {
            ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
            NSLog(@"%@",twitterAccount.username);
            NSLog(@"%@",twitterAccount.accountType);
        }
    }
}];

这篇关于在iOS 6中获取真正的推特用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆