如何使用划线员在Grails中为Twitter实现仅应用程序身份验证?

编程入门 行业动态 更新时间:2024-10-26 05:25:53
本文介绍了如何使用划线员在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实现仅应用程序身份验证?

本文发布于:2023-11-26 16:44:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634418.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   中为   应用程序   身份验证   Grails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!