簡體   English   中英

使用Twitter API的401未經授權的錯誤

[英]401 Unauthorized error using twitter API

對於此Twitter API請求,我總是收到401 Unauthorized響應。 這令人困惑,因為我有一個Twitter會話並正在簽署請求。 提前致謝。

    NSURL *retweetAPIURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/retweet/%@.json", tweetID]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:retweetAPIURL];
request.HTTPMethod = @"POST";

if (self.twitterSession) {

    [self.twitterSession signRequest:request];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        block(nil, responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        block(error, nil);
    }];

    [[NSOperationQueue mainQueue] addOperation:operation];
} else {
    block([self createErrorWithMessage:NSLocalizedString(NSLocalizedString(@"TWITTER LOGIN ERROR", nil), nil)], nil);
}

您確定請求已簽名嗎? 您為什么不只使用SLRequest

NSURL *retweetAPIURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/retweet/%@.json", tweetID]];
ACAccount *account = // ...;
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:retweetAPIURL parameters:nil];
request.account = account;

NSURLRequest *preparedURLRequest = [request preparedURLRequest];

// create your AFHTTPRequestOperation using preparedURLRequest

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM