在iOS中从Twitter框架获取Twitter句柄

在iOS中从Twitter框架获取Twitter句柄,ios,twitter,frameworks,handle,Ios,Twitter,Frameworks,Handle,我知道,要在iOS 5中使用twitter框架访问已配置的twitter帐户,可以执行以下操作: ACAccountStore *t_account = [[ACAccountStore alloc] init]; ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; [account requestAccessToAccountsWi

我知道,要在iOS 5中使用twitter框架访问已配置的twitter帐户,可以执行以下操作:

ACAccountStore *t_account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
    if (granted == YES) {
    }
}

但问题是,我不需要一个完整的帐户,我只需要twitter名称,如果他在twitter帐户上配置了任何帐户。那么,有没有一种方法可以在不请求任何用户权限的情况下从框架(而非完整帐户)中获取推特句柄

如果用户不授予访问这些帐户的权限,您将无法访问任何帐户。只需在新项目中的应用程序代理中尝试以下内容,您就可以知道应用程序尚未获得访问twitter帐户的权限。当然,请确保您在设备上或模拟器中至少有一个twitter帐户,并且在项目和应用程序委托中导入帐户框架。您还假设用户只有一个twitter帐户。最好针对一个用户可能有多个帐户的情况编写代码

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    // Create an account type that ensures Twitter accounts are retrieved.
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

    for (ACAccount *account in accountsArray ) {
        NSLog(@"Account name: %@", account.username);
    }

    NSLog(@"Accounts array: %d", accountsArray.count);
现在更改代码以在用户授予权限时返回结果:

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    // Create an account type that ensures Twitter accounts are retrieved.
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {

    if(granted) {

        NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

        for (ACAccount *account in accountsArray ) {
            NSLog(@"Account name: %@", account.username);
        }

        NSLog(@"Accounts array: %d", accountsArray.count);
    }
}];

所以我想简单的回答是,苹果要求用户授予用户帐户权限是有原因的。如果未授予该访问权限,您将无法获取任何数据

是啊!我知道这一点。现在我不认为有任何方法可以通过“用户权限弹出窗口”,即使我不想要完整的帐户。我只是想要用户的twitter句柄(如果twitter帐户中配置了),这就是我试图用更多的代码示例来回答的原因。除非:[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL-grated,NSError*error),否则您无权访问任何twitter帐户的任何信息感谢Michael,我已经尝试了所有这些。但我希望苹果可能有两种不同的帐户访问模式:1)可以读取并知道twitter用户名。2)可以拥有完整的twitter帐户,以便能够读取/写入/向帐户发布任何数据。没问题。只要获得句柄就好了,但我明白了,如果用户不允许访问他们的任何帐户信息,为什么他们甚至不给我们这些信息。