-(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];
}];
}
现在,响应数据包含以下内容:
(lldb) po resp
{
errors = (
{
code = 92;
message = "SSL is required";
}
);
}
好了,twitter现在需要SSL。讨论的是https://dev.twitter.com/discussions/24239。
我应该如何更改我的代码?
发布于 2014-03-25 11:51:54
SLRequest
具有account
属性。您需要将其设置为用户的twitter帐户(这是从ACAccountStore
类获得的ACAccount
对象。
如果设置此选项,则会对连接进行身份验证,并为您执行OAuth。
因此,您需要执行以下操作:
requestAccessToAccountsWithType:...
ACAccountStore
对象ACAccount
对象SLRequest
对象。发布于 2014-07-07 15: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://“。
下面是完整的代码,可以帮助你更好地理解:
- (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");
}
}];
}
https://stackoverflow.com/questions/22631593
复制相似问题