-(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是讨论。
我应该如何更改我的代码?
答案 0 :(得分:0)
SLRequest
具有account
属性。您需要将此设置为用户的Twitter帐户(这是您从ACAccount
班级获得的ACAccountStore
个对象。
如果设置此项,则会对连接进行身份验证,并为您执行OAuth。
因此,您需要执行以下操作:
ACAccountStore
对象requestAccessToAccountsWithType:...
ACAccount
对象
SLRequest
对象。答案 1 :(得分:0)
当我使用网址NSURL *requestURL = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"];
但是我通过更改网址来解决了这个错误:NSURL *requestURL = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/update.json"];
- >错误message = "SSL is required"
表示将对所有api.twitter.com网址强制执行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");
}
}];
}