在iOS中使用Twitter Framework处理Twitter

在iOS中使用Twitter Framework处理Twitter,第1张

概述我知道要在iOS 5中使用twitter框架访问已配置的Twitter帐户,可以执行以下 *** 作: ACAccountStore *t_account = [[ACAccountStore alloc] init];ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdent 我知道要在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);    }}];

所以我想简短的回答是,苹果要求用户授予用户帐户权限是有原因的.如果未授予该访问权限,则不会获得任何数据.

总结

以上是内存溢出为你收集整理的在iOS中使用Twitter Framework处理Twitter全部内容,希望文章能够帮你解决在iOS中使用Twitter Framework处理Twitter所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/999435.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存