2014-03-25 43 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"); 
     } 
    }]; 
}