twitter4J,jquery,coldfusion集成 [英] twitter4J, jquery, coldfusion integration

查看:164
本文介绍了twitter4J,jquery,coldfusion集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Twitter4j,并尝试获取用户的Twitter访问令牌并将其存储到数据库中,以便稍后进行发推文.我想完全使用jQuery和Ajax来完成此操作,而无需进行任何操作.

I'm using Twitter4j and attempting to obtain and store user's Twitter access tokens to database for later tweeting. I want to do it entirely with jQuery and ajax, silently.

我有一个具有必要基本功能的cfc.例如接下来的jquery调用cfc函数,该函数生成requestURL并弹出打开Twitter身份验证窗口.

I have a cfc with the basic functions necessary. e.g. tHe following jquery calls a cfc function which generates the requestURL and pops open a Twitter auth window.

$(".cbLinkTwitter").live("click", function(e) {
     $.getJSON(cfcRoot + "/twitter.cfc?method=getRequestURL&returnformat=json, {"user_id":user_id}, function(res,code) {
          openWindow(res);
     });
     e.preventDefault();
});

一切正常.但是,在用户授予授权后,如何使用jQuery捕获返回的令牌.它需要返回到指定的回调URL,但是我希望它在可能的情况下以静默方式返回数据.可以使用iframe完成吗?

This is all working fine. However after the user grants authorisation, how to I use jQuery to capture the returned tokens. It needs to return to a specified callback URL, but I would like it to return the data silently if possible. Could this be done with an iframe?

我可能要问的太多了,但是如果有人做过类似的事情,我将非常感激朝正确方向前进.

I'm probably asking too much, but if anyone's done anything similar, I'd really appreciate a shove in the right direction.

推荐答案

看看此处.

Have a look here.

此站点的工作方式是使用getOAuthRequestToken()生成RequestToken,然后在RequestToken上调用getToken()getSecretToken()并将这两个变量存储在SESSION范围内.然后,使用getAuthorizationURL()生成授权URL.

The way this site does it is by generating a RequestToken using getOAuthRequestToken(), then call getToken() and getSecretToken() on the RequestToken and store those 2 variables in the SESSION scope. Then the Authorization URL is generated using getAuthorizationURL().

用户批准OAuth请求后,您需要生成访问令牌并存储这两种方法的结果:AccessToken.getToken()AccessToken.getTokenSecret().

After the user has approved the OAuth request, you need to generate an Access Token and store the results of those 2 methods: AccessToken.getToken() and AccessToken.getTokenSecret().

因此,为了回答您的问题,我以为它会起作用,那就是在生成并返回授权URL之前存储oAuthRequestTokenoAuthRequestTokenSecretSESSION范围.

So to answer your question, the way I'd assume it would work, would be to store your oAuthRequestToken and oAuthRequestTokenSecret is SESSION scope before generating and returning the Authorization URL.

在Twitter上注册应用程序时,请指定一个回调URL.用户在Twitter上自动完成您的应用程序后,该页面将被重定向到该用户.

When you register your application with Twitter, you specify a callback URL. That's the page where the user is going to be redirected after the user autorizes your application on Twitter.

调用回调URL时,只需根据存储在SESSION sope中的请求令牌创建访问令牌.

When the callback URL is called, simply create an Access Token from the request token stored in SESSION sope.

<cfset AccessToken = Twitter.getOAuthAccessToken(Session.oAuthRequestToken,Session.oAuthRequestTokenSecret) />

并将令牌和令牌秘密存储在数据库中:

and store the Token and TokenSecret in database:

<cfset Token = AccessToken.getToken() />
<cfset TokenSecret = AccessToken.getTokenSecret() />

希望这会有所帮助

这篇关于twitter4J,jquery,coldfusion集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆