我正在为没有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"
如果有人能帮助我,那就太好了。
答案 0 :(得分:0)
允许您在没有用户身份验证的情况下获取搜索结果的API是版本1.0并且已显示,因此您需要使用某个Twitter库验证您的请求,此link将指导您如何执行此操作以及如何得到一个搜索结果。