سؤال

How to use TWRequest for both iOS 5 for getting Twitter User Details,

TWRequest was working earlier and I was using in this way

 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];

But recently, Twitter closed the api version 1 and implemented version 1.1, and Presently The above logic is not working in iOS 5, due to the API deprecation may be...

I am using SLRequest for iOS 6 it is working perfect, But I would like to know How can we get Twitter user details in iOS 5

هل كانت مفيدة؟

المحلول

Try this :

   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];
                             }                             
                         });
                     }];
                 });
             }
         }];
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top