无需用户身份验证即可获取搜索结果 [英] Get Search Results without user authentication

查看:34
本文介绍了无需用户身份验证即可获取搜索结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为没有 Twitter 的用户构建应用程序,因此无法进行用户身份验证.我让它与用户时间线一起工作,但不能与搜索一起工作.

I am building a app for users who don't have Twitter, so user authentication is impossible. I got it working with the user timeline but not with search.

我从 Twitter 收到了这个错误:

I got this error back from 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 命令行字符串:

Here is the cURL command line string:

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"

如果有人能帮助我,那就太好了.

If somebody could help me it would be great.

推荐答案

允许你在没有用户身份验证的情况下获取搜索结果的 API 是 1.0 版并且它是显示出来的,所以你需要用一些 twitter 库来验证你的请求,这个 <一个 href="https://stackoverflow.com/questions/17207317/ios-how-to-fetch-tweet-from-twitter-api-1-1/17207745#17207745">链接 将指导你如何这样做以及如何获得搜索结果.

The API which allow you to get search results without user authentication is Version 1.0 and it's displayed, so you need to authenticate your request with some twitter library, this link will guide you how to do that and how to get a search result.

这篇关于无需用户身份验证即可获取搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆