ios - 在 iOS 中使用 SSL 连接到 Twitter API

标签 ios ssl twitter

我尝试使用 iOS SDK 中的 Twitter API 获取用户的 Twitter 时间线,但收到错误消息:

代码 = 92; message = "需要 SSL";

我用谷歌搜索了这个错误,发现this page Twitter API 网站上有,但我不知道如何在 iOS 中使用它。

这是我的代码:

ACAccountStore *account = [[ACAccountStore alloc] init];

ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

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


     if (granted == YES){

         NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];


         if ([arrayOfAccounts count] > 0) {

             ACAccount *twitterAccount = [arrayOfAccounts lastObject]; 

             NSURL *requestAPI = [NSURL URLWithString:@"http://api.twitter.com/1.1/statuses/user_timeline.json"]; 


             NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];

             [parameters setObject:@"100" forKey:@"count"];

             [parameters setObject:@"1" forKey:@"include_entities"];



             SLRequest *posts = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestAPI parameters:parameters];

             posts.account = twitterAccount;



             [posts performRequestWithHandler:

              ^(NSData *response, NSHTTPURLResponse
                *urlResponse, NSError *error)
              {
                  // The NSJSONSerialization class is then used to parse the data returned and assign it to our array.

                  array = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];

                  if (array.count != 0) {

                      dispatch_async(dispatch_get_main_queue(), ^{
                          NSLog(@"%@",array);
                      });

                  }

              }];

         }

     } else {

         // Handle failure to get account access
         NSLog(@"%@", [error localizedDescription]);

     }

 }];

有办法解决这个问题吗?

最佳答案

在您的网址中使用“https”:

https://api.twitter.com/1.1/statuses/user_timeline.json

文档:https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline

关于ios - 在 iOS 中使用 SSL 连接到 Twitter API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22303771/

相关文章:

IOS 应用程序在后台运行时闪烁和响铃

java - 从 Java 程序到 mssql 的 SSL 连接

cocoa - 第二次将观察者添加到 NSNotificationCenter 导致 EXC_BAD_ACCESS

ios - Swift 中的卷积 CIFilter

performance - WebAPI 在同一台服务器上,即使在其上应用了 SSL,也可以通过 http 而不是 https 访问它吗?

html - 在页面中嵌入 Twitter 网络意图 "tweet box"

ruby-on-rails - Rails 如何处理模型中的错误和异常

Java 使用 Xpath 解析 XML 多级

ios - cordova platform add ios not working on mac(创建ios子项目时出错)

linux - perl 无法在 linux 上获取 SSL 套接字