我可以使用scribe使用streeming api获取带有特定标签的tweet吗?我在java工作,我想在appengine项目中使用scribe。有可能吗?我尝试以下代码:
OAuthService service = new ServiceBuilder()
.provider(TwitterApi.class)
.apiKey(MYCONSUMERKEY)
.apiSecret(MYCONSUMERSECRET)
.debug()
.build();
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
request.addBodyParameter("track", "prova");
Token requestToken = new Token(MYACCESSTOKEN,MYACCESSTOKENSECRET);
service.signRequest(requestToken, request);
Response response = request.send();
System.out.println(response.getBody());
}
答案是:
signing request: https://stream.twitter.com/1/statuses/filter.json
setting token to: Token[MYACCESSTOKEN,MYACCESSTOKENSECRET]
generating signature...
base string is: GET&https%3A%2F%2Fstream.twitter.com%2F1%2Fstatuses%2Ffilter.json&oauth_consumer_key%3DMYCONSUMERKEY%26oauth_nonce%3Dxxx%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3Dxxx%26oauth_token%3Dxxx%26oauth_version%3D1.0%26track%3Dprova
signature is: 5UU55rZqzjiaRwSNGz/jrcffPoM=
appended additional OAuth parameters: { oauth_signature -> xxx , oauth_version -> 1.0 , oauth_nonce -> xxx , oauth_signature_method -> HMAC-SHA1 , oauth_consumer_key -> MYCONSUMERKEY , oauth_token -> xxx , oauth_timestamp -> xxx }
using Http Header signature
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/1/statuses/filter.json'. Reason:
<pre> Unauthorized</pre>
1条答案
按热度按时间fjnneemd1#
正如我从代码中看到的,您正试图使用requesttoken对get调用进行签名,您必须首先获取一个accesstoken,然后使用这个accesstoken对任何get/post调用进行签名。试着这样做: