coldfusion twitter4j集成

时间:2011-10-14 08:11:05

标签: twitter coldfusion twitter4j

将twitter4j与coldfusion一起使用,我的回调页面出现以下错误:

OAuth consumer key/secret combination not supplied

我的授权电话如下:

<cfset o_twitter = createObject("component", "cfcs.twitter")>  
<cfset request_url = o_twitter.getRequestURL(user_id=url.user_id)>   
<!--- redirect to twitter auth --->
<cflocation url="#request_url#" addtoken="no">

o_twitter.getRequestURL如下所示:

<cffunction name="getRequestURL" access="remote" returntype="any" hint="Generates Twitter token request url">
    <cfargument name="twitter_consumer_key" type="string" default="#application.TwitterConsumerKey#">
    <cfargument name="twitter_consumer_secret" type="string" default="#application.TwitterConsumerSecret#">
    <cfargument name="user_id" type="any" required="false" default="">

    <cfset var o_twitter4j = createObject("java", "twitter4j.Twitter")>
    <cfset o_twitter4j.setOAuthConsumer(arguments.twitter_consumer_key,arguments.twitter_consumer_secret)>

    <!--- Generate request token and send user to twitter for allow/deny access --->
    <cfset RequestToken = o_twitter4j.getOAuthRequestToken()>
    <!--- set requestTokens in session for later swapping for user access tokens --->
    <cfset Session.oAuthRequestToken = RequestToken.getToken()>
    <cfset Session.oAuthRequestTokenSecret = RequestToken.getTokenSecret()>
    <cfset requestURL = RequestToken.getAuthorizationURL()>

    <cfreturn requestURL>
</cffunction>

回调

<cfscript>
    o_twitter4j = createObject("java", "twitter4j.Twitter");
    o_twitter = createObject("component","cfcs.twitter");
</cfscript>
<cfset AccessToken = o_twitter4j.getOAuthAccessToken(Session.oAuthRequestToken,Session.oAuthRequestTokenSecret)>

它到达回调页面,但最后一行的getOAuthAccessToken()方法出错。 谁知道我做错了什么?可能是不值得的东西。

1 个答案:

答案 0 :(得分:3)

错误消息非常自我解释 - 您没有提供消费者密钥/秘密。

您需要创建自己的Twitter应用here,然后您将获得消费者密钥和密码,以便您能够使用OAuth。