我正在为没有 Twitter 的用户构建一个应用程序,因此无法进行用户身份验证。我让它与用户时间轴一起使用,但不适用于搜索。
我从 Twitter 收到了这个错误:
{"errors":[{"message":"Could not authenticate you","code":32}]}
这是我的有效代码:
MKNetworkOperation *operation = [[MKNetworkOperation alloc] initWithURLString:@"https://api.twitter.com/1.1/statuses/user_timeline.json" params:[@{ @"screen_name" : user } mutableCopy] httpMethod:@"GET"];
[operation addHeaders:@{ @"Authorization" : [self OAuthHeaderForURL:[NSURL URLWithString:operation.url]] }];
[operation onCompletion:^(MKNetworkOperation *completedOperation) {
completionBlock([completedOperation responseJSON]);
} onError:^(NSError *error) {
NSLog(@"\n\n\nError bij User: %@", error);
}];
[self.networkEngine enqueueOperation:operation];
这是有问题的代码:
MKNetworkOperation *operation = [[MKNetworkOperation alloc] initWithURLString:@"https://api.twitter.com/1.1/search/tweets.json" params:[@{ @"q" : [NSString stringWithFormat:@"#%@", hashtag] } mutableCopy] httpMethod:@"GET"];
[operation addHeaders:@{ @"Authorization" : [self OAuthHeaderForURL:[NSURL URLWithString:operation.url]] }];
[operation onCompletion:^(MKNetworkOperation *completedOperation) {
completionBlock([completedOperation responseJSON]);
} onError:^(NSError *error) {
NSLog(@"\n\n\nError bij Hashtag: %@", error);
}];
[self.networkEngine enqueueOperation:operation];
这是 cURL 命令行字符串:
curl -X GET -H "Authorization: OAuth oauth_consumer_key="XizVPuR2LQcnL9xAzMo6AA", oauth_nonce="2806C6BC-5B67-42E4-BAC9-1D3F2D8A", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1371545629", oauth_version="1.0", oauth_token="74944468-tYmMuxMaaZUxiTHuZ78Y9qljCqCiPcfKvhavS9wuU", oauth_signature="6E1ggIZYIBrRQJ9i1LeqLQBM5fc%3D"" -H "Accept-Language: en, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us" "https://api.twitter.com/1.1/search/tweets.json?q=%23demeern"
如果有人可以帮助我,那就太好了。