本文介绍了如何使用划线员在Grails中为Twitter实现仅应用程序身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以前使用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('search.twitter/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.
dev.twitter/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, 'api.twitter/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实现仅应用程序身份验证?
发布评论