首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SLRequest推特访问现在需要SSL

SLRequest推特访问现在需要SSL
EN

Stack Overflow用户
提问于 2014-03-25 18:23:20
回答 2查看 971关注 0票数 0
代码语言:javascript
复制
-(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];
                    }];
                }

现在,响应数据包含以下内容:

代码语言:javascript
复制
(lldb) po resp
{
    errors =     (
                {
            code = 92;
            message = "SSL is required";
        }
    );
}

好了,twitter现在需要SSL。讨论的是https://dev.twitter.com/discussions/24239

我应该如何更改我的代码?

EN

回答 2

Stack Overflow用户

发布于 2014-03-25 19:51:54

SLRequest具有account属性。您需要将其设置为用户的twitter帐户(这是从ACAccountStore类获得的ACAccount对象。

如果设置此选项,则会对连接进行身份验证,并为您执行OAuth。

因此,您需要执行以下操作:

  • 使用requestAccessToAccountsWithType:...
  • Once访问权限创建ACAccountStore对象
  • 请求访问twitter帐户,从帐户存储中获取ACAccount对象
  • 将此对象添加到您的SLRequest对象。
票数 0
EN

Stack Overflow用户

发布于 2014-07-07 23:39:25

当我使用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"];

-> error message = "SSL is required"表示“将对所有api.twitter.com URL强制执行SSL要求,包括OAuth的所有步骤和所有REST API资源。”这意味着从现在开始,我们必须使用"https://“”而不是以前使用的http://“。

下面是完整的代码,可以帮助你更好地理解:

代码语言:javascript
复制
- (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");
        }
    }];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22631593

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档