coldfumonkeh / monkehTweets

A ColdFusion wrapper to interact with the Twitter API (with OAuth integration)
http://www.mattgifford.co.uk/
53 stars 30 forks source link

Error in base.cfc:checkStatusCode() #2

Closed RichardDavies closed 11 years ago

RichardDavies commented 12 years ago

While posting a retweet, I've recently started getting this error/exception:

The element at position 1 of dimension 1, of array variable "REQXML," cannot be found. The error occurred on line 263 [of base.cfc].

Apparently sometimes the xpath search on the previous line isn't finding any matches:

262:  <cfset reqXML = xmlSearch(arguments.data.FileContent,'hash/request') />
263:  <cfset stuErrInfo.api_Info.request = reqXML[1].XmlText />
coldfumonkeh commented 12 years ago

Thanks Richard. Is this using the latest version of the library?

RichardDavies commented 12 years ago

Using v1.3.2 downloaded from RiaForge.

RichardDavies commented 12 years ago

Any update on this? I continue to get this error message.

coldfumonkeh commented 12 years ago

Looking in to it now.

coldfumonkeh commented 12 years ago

@RichardDavies - it appears that Twitter have changed the format of their error responses, which is why this issue is occurring. Previously, the XML response contained a hash/request node. Now it appears to include simply an errors/error node with the status code as an attribute:

https://dev.twitter.com/docs/error-codes-responses

I'll get this resolved asap. In the meantime, any idea why you are getting the errors in the first place? Are your calls to the retweet method constructed properly with the correct parameters? If you can post any code samples that would help.

Many thanks

RichardDavies commented 12 years ago

My code is in a scheduled task that aggregates tweets from a variety of Twitter accounts into a combined RSS feed. In addition, it also retweets those tweets on a central twitter account. The task runs every minute and attempts to retweet any tweets from the last 10 minutes. It relies on Twitter's "anti duplication" logic to avoid duplicate retweets of the same tweets. Perhaps maybe now it returns an error when it tries to retweet something that I've already retweeted?

<!--- Retweet aggregated tweets on main account --->
<cfif feedurl contains "twitter.com">
    <!--- Extract tweet ID from link in GUID RSS element --->
    <cfset matches = REMatch("\d+$", feedXML.rss.channel.item[x].guid.xmlText) />
    <cfset id = matches[1] />

    <!--- Only retweet recent alerts --->
    <cfset utcHourOffset = NumberFormat(GetTimeZoneInfo().utcHourOffset, "+09") & "00">
    <cfset pubdate = Replace(feedXML.rss.channel.item[x].pubdate.xmlText, "+0000", utcHourOffset) />
    <cfset pubdate = ParseDateTime(pubdate, "pop") />
    <cfset startdate = DateAdd("n", -10, Now()) />
    <cfif DateCompare(pubdate, startdate) eq 1>
        <cfset Application.twitter.retweet(id, true) />
    </cfif>
</cfif>
RichardDavies commented 12 years ago

FYI: I took another look at my code and realized it appears this error happens if I try to retweet one of my own tweets.

RichardDavies commented 12 years ago

It also appears to be happening if I try to retweet the same tweet more than once (previously it just ignored the duplicate retweet request.)

RichardDavies commented 12 years ago

This is the error result being returned by twitter:

<?xml version="1.0" encoding="UTF-8"?>
<errors>
  <error>sharing is not permissable for this status (Share validations failed)</error>
  <error>sharing is not permissable for this status (Share validations failed)</error>
  <error>sharing is not permissable for this status (Share validations failed)</error>
</errors>
coldfumonkeh commented 12 years ago

Hi Richard. I've updated the repository with majorly amended code which now uses Twitter API 1.1. The current API version will be dropped in March 2013, so I wanted to stay ahead and get people ready. The new API only manages with JSON format responses and data. As a result, I've dropped the checkStatusCode and handleReturnFormat methods entirely as the JSON error responses will be returned for users to catch and manage.