gpt4 book ai didi

ios - 使用 twitter API 时出现 401 未经授权的错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:04 24 4
gpt4 key购买 nike

对于此 Twitter API 请求,我总是收到 401 Unauthorized 响应。这很令人困惑,因为我有一个 Twitter session 并正在签署请求。提前致谢。

    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

关于ios - 使用 twitter API 时出现 401 未经授权的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22129292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com