【问题标题】:Objective-C Twitter API 150 RequestsObjective-C Twitter API 150 个请求
【发布时间】:2012-07-05 09:56:51
【问题描述】:

我正在尝试使用 NSURLConnection 从 twitter 获取推文,并且我一直在达到每小时的最大请求数 (150)。我切换到使用经过身份验证的方式来获取推文,如下所示,但仍然达到最大 API 调用次数 - 150。我如何才能在每台设备上发出超过 150 个推文请求?

ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType = 
[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

//  Request permission from the user to access the available Twitter accounts
[store requestAccessToAccountsWithType:twitterAccountType 
                 withCompletionHandler:^(BOOL granted, NSError *error) {
                     if (!granted) {
                         // The user rejected your request 
                         NSLog(@"User rejected access to the account.");
                     } 
                     else {
                         // Grab the available accounts
                         NSArray *twitterAccounts = 
                         [store accountsWithAccountType:twitterAccountType];

                         if ([twitterAccounts count] > 0) {
                             // Use the first account for simplicity 
                             ACAccount *account = [twitterAccounts objectAtIndex:0];

                             // Now make an authenticated request to our endpoint
                             NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
                             [params setObject:@"1" forKey:@"include_entities"];

                             //  The endpoint that we wish to call
                             NSURL *url = 
                             [NSURL 
                              URLWithString:@"https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=%@&count=5",someTwitterUserName];

                             //  Build the request with our parameter 
                             TWRequest *request = 
                             [[TWRequest alloc] initWithURL:url 
                                                 parameters:params 
                                              requestMethod:TWRequestMethodGET];

                             // Attach the account object to this request
                             [request setAccount:account];

                             [request performRequestWithHandler:
                              ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                                  if (!responseData) {
                                      // inspect the contents of error 
                                      NSLog(@"%@", error);
                                  } 
                                  else {
                                      NSError *jsonError;
                                      NSArray *timeline = 
                                      [NSJSONSerialization 
                                       JSONObjectWithData:responseData 
                                       options:NSJSONReadingMutableLeaves 
                                       error:&jsonError];            
                                      if (timeline) {                          
                                          // at this point, we have an object that we can parse and grab tweet information from
                                          NSLog(@"%@", timeline);
                                      } 
                                      else { 
                                          // inspect the contents of jsonError
                                          NSLog(@"%@", jsonError);
                                      }
                                  }
                              }];

                         } // if ([twitterAccounts count] > 0)
                     } // if (granted) 
                 }];

【问题讨论】:

  • 如果他们有 150 个限制,我敢肯定你不能。
  • 我想你的意思是[NSURL URLWithString: [NSString stringWithFormat: @"https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=%@&count=5", someTwitterUserName]]

标签: objective-c ios twitter


【解决方案1】:

试试看这篇文章

solution

你的 twitter 应用程序中的问题,默认有限制

【讨论】:

  • 错误:“超出速率限制。客户端每小时发出的请求不得超过 150 个。”每台设备每小时发出的请求不得超过 150 个,我希望发出超过 150 个。
猜你喜欢
  • 2011-02-27
  • 2018-01-07
  • 2011-05-30
  • 1970-01-01
  • 2022-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-11
相关资源
最近更新 更多