[英]How to implement application-only authentication for twitter in Grails using scribe?
Earlier i was using GET search/tweets of Twitter API 1.0 To get tweets according to #tags in Grails 早些时候我使用的是Twitter API 1.0的GET搜索/推文,根据Grails中的#tags获取推文
Map jsonMap = grails.converters.JSON.parse(new URL('http://search.twitter.com/search.json?q=%23' + URLEncoder.encode(tag) + '&offset=' + offset + 'result_type=mixed&lang=en&page=' + page).text)
But due to change in Twitter API version 1.1 now the above call requires Authentication. 但是由于Twitter API版本1.1中的更改,上述调用需要身份验证。
I want to fetch tweets on behalf of Application(Authentication) not by user Authentication. 我想代表应用程序(身份验证)而不是用户身份验证来获取推文。
Is this possible? 这可能吗?
I came across application-only-auth but unable to implement it. 我遇到了仅应用程序身份验证,但是无法实现它。
https://dev.twitter.com/docs/auth/application-only-auth https://dev.twitter.com/docs/auth/application-only-auth
How to implement above using scribe API in Grails. 如何在Grails中使用scribe API实施上述操作。
I have done like this and it worked for me. 我已经做到了,它对我有用。
OAuthService service = new ServiceBuilder().provider(TwitterApi.class).apiKey(grailsApplication.config.oauth.providers.twitter.key).apiSecret(grailsApplication.config.oauth.providers.twitter.secret).build()
OAuthRequest request = new OAuthRequest(Verb.GET, 'https://api.twitter.com/1.1/search/tweets.json?q=%23' + URLEncoder.encode(tag) + '&count=100&result_type=mixed&lang=en');
Token accessToken = new Token(grailsApplication.config.oauth.providers.twitter.accessToken, grailsApplication.config.oauth.providers.twitter.accessSecret)
service.signRequest(accessToken, request);
Response response = request.send();
JSONElement jsonMap = grails.converters.JSON.parse(response.getBody());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.