Question

I am not writing the same question again but need the solution for it . Which queried that how to make application only authentication for twitter in grails.

below is the link for the same

How to implement application-only authentication for twitter in Grails using scribe? also

Twitter application authentication to get user timelines for single user account

any help will be greatly admired .

thanks

No correct solution

OTHER TIPS

You can do it simply:

import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH

...

def requestResourceForTwitter(Token token, String url) {    
    String appAttribute = GrailsApplicationAttributes.APPLICATION_CONTEXT
    Object appContext = SCH.servletContext.getAttribute(appAttribute)
    def oauthService = appContext.oauthService
    Response response = oauthService.getTwitterResource(token, url)
    if(response.code == 200){
        return JSON.parse(response.body)
    }
}

you need to do something like this and this is working 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());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top