[英]SLRequest twitter access now requires SSL
-(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是討論。
我應該如何更改我的代碼?
SLRequest
具有一個account
屬性。 您需要將此設置為用戶的twitter帳戶(這是從ACAccountStore
類獲取的ACAccount
對象。
如果設置了此設置,則連接將通過身份驗證,並會為您執行OAuth。
因此,您需要執行以下操作:
ACAccountStore
對象 requestAccessToAccountsWithType:...
請求訪問Twitter帳戶 ACAccount
對象 SLRequest
對象。 當我使用URL NSURL *requestURL = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"];
時,我確實得到了相同的錯誤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"];
->錯誤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");
}
}];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.