2014-03-25 76 views
0
-(void) vSLRequest:(SLRequest*) SLRequest1 WithHandler:(NSString *) errorTitle andD1: (NSString *) errorDescription FP1:(NSString *) errorParse FP2:(NSString *) errorParseDesc ifSuccess:(void(^)(NSDictionary * resp))succesBlock 
{ 
    [self vSuspendAndHaltThisThreadTillUnsuspendedWhileDoing:^{ 
     [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 
      [SLRequest1 performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
       if(error != nil) { 
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{ 
         [[[UIAlertView alloc] initWithTitle:errorTitle message:errorDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]show]; 
        }]; 
       } 

現在的響應數據包含以下內容:SLRequest Twitter的訪問,現在需要SSL

(lldb) po resp 
{ 
    errors =  (
       { 
      code = 92; 
      message = "SSL is required"; 
     } 
    ); 
} 

好了,所以,微博現在需要SSL。 https://dev.twitter.com/discussions/24239是討論。

我該如何更改我的代碼?

回答

0

SLRequest有一個account屬性。您需要將其設置爲用戶的Twitter帳戶(這是一個ACAccount對象,你從ACAccountStore類獲得。

如果設置此,連接認證和OAuth爲您進行。

所以,你需要做到以下幾點:

  • 創建使用requestAccessToAccountsWithType:...
  • 到Twitter賬戶申請權限授予訪問權後的ACAccountStore對象,得到ACAccount來自帳戶存儲區的對象
  • 將此項添加到您的SLRequest對象中。
0

我沒有得到同樣的錯誤,當我用URL NSURL *requestURL = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"];

但我通過改變URL這個解決了這個錯誤:NSURL *requestURL = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/update.json"];

- >錯誤message = "SSL is required"說,「SSL要求將強制執行包括所有api.twitter.com網址,包括OAuth和所有REST API資源的所有步驟。「 這意味着現在我們必須使用「https://」而不是我們以前使用的「http://」。

下面是全部代碼,這將有助於你更好地理解:

- (void) postTweet 
{ 
    ACAccountStore *account = [[ACAccountStore alloc] init]; 
    ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierTwitter]; 

    [account requestAccessToAccountsWithType: accountType 
            options: nil 
            completion: ^(BOOL granted, NSError *error) 
    { 
     if (granted == YES){ 

      // Get account and communicate with Twitter API 
      NSLog(@"Access Granted"); 

      NSArray *arrayOfAccounts = [account 
             accountsWithAccountType:accountType]; 

      if ([arrayOfAccounts count] > 0) { 

       ACAccount *twitterAccount = [arrayOfAccounts lastObject]; 

       NSDictionary *message = @{@"status": @"My First Twitter post from iOS 7"}; 

       NSURL *requestURL = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/update.json"]; 

       SLRequest *postRequest = [SLRequest requestForServiceType: SLServiceTypeTwitter 
                  requestMethod: SLRequestMethodPOST 
                     URL: requestURL 
                   parameters: message]; 

       postRequest.account = twitterAccount; 

       [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) 
       { 
        NSLog(@"Twitter HTTP response: %i", [urlResponse statusCode]); 
        NSLog(@"Twitter ResponseData = %@", [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error]); 
       }]; 
      } 
     } 
     else { 

      NSLog(@"Access Not Granted"); 
     } 
    }]; 
}