如何使用划线员在Grails中为Twitter实现仅应用程序身份验证? [英] How to implement application-only authentication for twitter in Grails using scribe?
问题描述
我以前使用Twitter API 1.0的GET搜索/推文来根据Grails中的#tags获取推文
Earlier i was using GET search/tweets of Twitter API 1.0 To get tweets according to #tags in Grails
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)
但是由于Twitter API版本1.1的更改,上述调用需要身份验证.
But due to change in Twitter API version 1.1 now the above call requires Authentication.
我想代表应用程序(身份验证)而不是通过用户身份验证来获取推文.
I want to fetch tweets on behalf of Application(Authentication) not by user Authentication.
这可能吗?
我遇到了application-only-auth,但无法实现.
I came across application-only-auth but unable to implement it.
https://dev.twitter.com/docs/auth/application-仅授权
如何在Grails中使用scribe API实施上述操作.
How to implement above using scribe API in Grails.
推荐答案
我已经做到了,并且对我有用.
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());
这篇关于如何使用划线员在Grails中为Twitter实现仅应用程序身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!