2014-06-12 35 views
0

我試圖使用SLRequest發出推特請求,但每當我在請求中包含參數時,我得到的響應是{"errors":[{"message":"Could not authenticate you","code":32}]}。如果我不包含參數,請求按預期工作。使用帶參數的SLRequest的Twitter請求中的錯誤32

我試過在URL中包含參數作爲查詢字符串,但它沒有區別。

這裏是我的代碼:

ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) { 
    if (granted) { 
     NSArray *twitterAccounts = [accountStore accountsWithAccountType:accountType]; 

     if (twitterAccounts.count == 0) { 
      NSLog(@"There are no Twitter accounts configured. You can add or create a Twitter account in Settings."); 
     } 
     else { 
      ACAccount *twitterAccount = [twitterAccounts firstObject]; 

      SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/home_timeline.json"] parameters:@{@"count": @10}]; 
      request.account = twitterAccount; 

      [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
       NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 

       NSLog(@"%@", responseString); 
      }]; 
     } 
    } 
}]; 

回答

0

在我看來就像你無法通過@ 10的整數 - 嘗試,而不是把它當作一個字符串:@「10」。

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET 
         URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/home_timeline.json"] 
         parameters:@{@"count": @"10"}]; 
              //^

這裏有一個Twitter doc with an example

+0

就是這樣,謝謝!不敢相信我沒有注意到它 –

+0

:D它發生在我身上,正是在實際之前,所以不用擔心。 – brandonscript