I'm trying to make a script that will automatic post from my blog to
my Twitter account.

I have everything registered on the Twitter and I have the
TwitterConsumerKey, TwitterConsumerSecret.

Here is my question:

If I run this script, it will leave my website go to Twitter and ask
if I want to accept the application or now.
<cfset TwitterConsumerKey = "xxxx">
<cfset TwitterConsumerSecret = "xxxxx">
<cfset Twitter = createObject("java", "twitter4j.Twitter")>
<cfset
Twitter.setOAuthConsumer(TwitterConsumerKey,TwitterConsumerSecret)>
<cfif structKeyExists(url,'oauth_token') IS FALSE>
<!--- // 2. Authorize --->
        <cfset RequestToken = Twitter.getOAuthRequestToken()>
        <cfset Session.oAuthRequestToken = RequestToken.getToken()>
        <cfset Session.oAuthRequestTokenSecret =
RequestToken.getTokenSecret()>
        <cflocation url="#RequestToken.getAuthorizationURL()#"
addtoken="No">
<cfelse>
        <!--- // 3. Authenticate // --->
        <cfset AccessToken =
Twitter.getOAuthAccessToken(Session.oAuthRequestToken,Session.oAuthRequestTokenSecret)>
        <cfset session.StoredAccessToken = AccessToken.getToken()>
        <cfset session.StoredAccessSecret = AccessToken.getTokenSecret()>
    <cfset
Twitter.setOAuthAccessToken(Session.StoredAccessToken,Session.StoredAccessSecret)>
        <cfset ID = Twitter.getId()>
    <cfdump var="#session#">
    <cfdump var="#ID#">
</cfif>

Everything work fine, and I can see the result.

I saved the AccessToken and AccessSecret for later use and when I use
this code it does not work:
<!--- TWITTER API INFO --->
<cfset TwitterConsumerKey = "xxxxx">
<cfset TwitterConsumerSecret = "xxxxx">
<!--- TWITTER TOKEN --->
<cfset StoredAccessToken = "xxxxx">
<cfset StoredAccessSecret = "xxxxxxx">

<cfset Twitter = createObject("java", "twitter4j.Twitter")>
<cfset Twitter.init()>
<cfset
Twitter.setOAuthConsumer(TwitterConsumerKey,TwitterConsumerSecret)>
<cfset
Twitter.setOAuthAccessToken(StoredAccessToken,StoredAccessSecret)>
<cfset Twitter.getId()>
<cfdump var="#Twitter.getId()#">

I keep getting this error

401:Authentication credentials were missing or incorrect. {"request":"/
1/account/verify_credentials.json","error":"Invalid / expired Token"}
null

Thanks for the help... I'm new to OAuth

-- 
Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group: 
http://groups.google.com/group/twitter-development-talk?hl=en

Reply via email to