首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用iOS TWRequest for iOS 5获取Twitter用户详细信息

如何使用iOS TWRequest for iOS 5获取Twitter用户详细信息
EN

Stack Overflow用户
提问于 2013-07-31 07:39:59
回答 1查看 471关注 0票数 0

如何将TWRequest用于iOS 5以获取Twitter用户详细信息,

TWRequest之前就在工作,我用的是这种方式

代码语言:javascript
复制
 NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/users/show.json"];
 NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:twittername,@"screen_name",nil];
                                 request = [[TWRequest alloc] initWithURL:url
                                                                      parameters:params
                                                                   requestMethod:TWRequestMethodGET];

但是最近,推特关闭了deprecation 1并实现了1.1版本,目前iOS 5中的上述逻辑无法工作,因为deprecation可能是.

我正在为SLRequest 6使用iOS 6,它运行得很好,但是我想知道如何在iOS 5中获取Twitter用户的详细信息。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-31 07:56:52

试试这个:

代码语言:javascript
复制
   NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/users/show.json"];
   NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:twittername,@"screen_name",nil];
   request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodGET];                                                                 

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *twitterAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    NSArray *twitterAccounts = [accountStore accountsWithAccountType:twitterAccountType];

    // Runing on iOS 6
    if (NSClassFromString(@"SLComposeViewController") && [SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
    {
        [accountStore requestAccessToAccountsWithType:twitterAccountType options:NULL completion:^(BOOL granted, NSError *error)
         {
             if (granted)
             {
                 SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url                                      parameters:parameters];

                 [request setAccount:[twitterAccounts lastObject]];

                 dispatch_async(dispatch_get_main_queue(), ^                                
                 {

                     [NSURLConnection sendAsynchronousRequest:request.preparedURLRequest queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response1, NSData *data, NSError *error)                      
                     {                         
                         dispatch_async(dispatch_get_main_queue(), ^                                        
                         {                             
                             if (data)                                 
                             {                                 
                                 [self loadData:data];                                 
                             }                             
                         });                                         
                     }];                     
                 });
             }
         }];
    }
    else if (NSClassFromString(@"TWTweetComposeViewController") && [TWTweetComposeViewController canSendTweet]) // Runing on iOS 5
    {
        [accountStore requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error)
         {
             if (granted)
             {
                 TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:parameters requestMethod:TWRequestMethodGET];
                 [request setAccount:[twitterAccounts lastObject]];

                 dispatch_async(dispatch_get_main_queue(), ^                                
                 {                     
                     [NSURLConnection sendAsynchronousRequest:request.signedURLRequest queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response1, NSData *data, NSError *error)                      
                     {                         
                         dispatch_async(dispatch_get_main_queue(), ^                                        
                         {                             
                             if (data)                                 
                             {                                 
                                 [self loadData:data];
                             }                             
                         });
                     }];
                 });
             }
         }];
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17964388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档