OGeek|极客世界-中国程序员成长平台

标题: ios - 在 iOS 中使用 SSL 连接到 twitter API [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 06:51
标题: ios - 在 iOS 中使用 SSL 连接到 twitter API

我正在尝试使用 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]);

     }

 }];

有没有办法解决这个问题?



Best Answer-推荐答案


在您的网址中使用“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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4