iphone - iOS 5 中的 Twitter 用户 ID

标签 iphone objective-c ios twitter

我在 iOS 5 中使用以下代码从 Twitter 获取用户详细信息。

if ([TWTweetComposeViewController canSendTweet]) 
{
    // Create account store, followed by a Twitter account identifer
    account = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    // Request access from the user to use their Twitter accounts.
    [account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) 
     {
         // Did user allow us access?
         if (granted == YES)
         {
             // Populate array with all available Twitter accounts
             arrayOfAccounts = [account accountsWithAccountType:accountType];
             [arrayOfAccounts retain];

             // Populate the tableview
             if ([arrayOfAccounts count] > 0) 
                 [self performSelectorOnMainThread:@selector(updateTableview) withObject:NULL waitUntilDone:NO];
         }
     }];
}

//

-(void)updateTableview
{

    numberOfTwitterAccounts = [arrayOfAccounts count];
    NSLog(@"Twiter details-- %@",[arrayOfAccounts objectAtIndex:0]);

}

在我的 NSLog 控制台中,我得到如下输出:

Twiter details-- type:com.apple.twitter  
identifier: E8591841-2AE0-4FC3-8ED8-F286BE7A36B0
accountDescription: @Sadoo55
username: sadukoyghdkwed@gmail.com
objectID: x-coredata://F8059811-CFB2-4E20-BD88-F4D06A43EF11/Account/p8
enabledDataclasses: {(
)}
properties: {
  "user_id" = 308905856;
}
parentAccount: (null)
owningBundleID:com.apple.Preferences

我想从中获取“user_id”。如何获取“user_id”(即 308905856)?

最佳答案

这是我在 iOS5 和 iOS6 中获取 user_id 所做的。

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

关于iphone - iOS 5 中的 Twitter 用户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9080135/

相关文章:

ios - 尽管启用了透明度,但半透明的导航和标签栏看起来不透明

ios - Swift 在 uicollectionview 中插入一个单元格给我一个错误

ios - 带主键的sqlite插入

ios - 从 UIImage 获取数据时内存泄漏

iphone - 如何更改 UILabel 的大小

iphone - 获取联系人图片 ios

ios - 如何将字幕从 uitableview 推送到详细 View Controller

iphone - CATransaction 没有动画

ios - 尝试将 PanoramaGL 添加到静态库时出现未知类型名称 'CGFloat'

iphone - 如何打印或记录 CGSize 对象的值?