Twitter module's nodeapi updates user's twitter status while user is logged on, but not when node is created remotely

flacorps - June 27, 2009 - 15:11
Project:Twitter
Version:6.x-2.5
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Issue tags:401, mailhandler, nodeapi
Description

I've included a call to the twitter_nodeapi function from the mailhandler for the creation of a user's blog entry node. So long as there was a global twitter account in place, the title and tinyurl of the mailed-in nodes tweeted out to the global twitter account's followers. But I wanted the tweets to go to the user's followers, not the site's followers.

Fast forward to the removal of the global twitter account and the storing of individual users' own twitter accounts by the twitter module. Users creating blog entries on the site and checking the box to tweet those blog entries experience no problems (tweets of title and tinyurl go out just fine), however the mailed-in blog entries post correctly to the site as the users' blog entries but are not tweeted, even though the code to invoke the twitter module that I put in the mailhandler module is unchanged.

While under 2.3 I created a watchdog call that was returning the 401 errors coming back from twitter.com's api to the log. I upgraded to 2.5 to see if the issue would be resolved, but still no tweets on the e-mailed nodes (haven't put a watchdog on it yet, but I'm assuming the same 401s would result). Interestingly, I was noticing that the twitter_nodeapi function was attempting to update the twitter status twice (resulting in two errors in the log) on the mailed-in nodes. Also while under 2.3 I put a watchdog call in for the both the successful and failed tweets and although the call attempted to log both the user's twitter account and password, the log entry on the successful ones (created on the site) would contain only the account, not the password (I'm assuming due to something I don't know regarding whether the password can be returned and how it should be done if it can be done--I was calling for it the exact same way I was calling for the account). For the failed tweets from the mailed-in nodes I did not even see the account.

Since the node->uid is necessary to create the node and seems to be what the twitter_nodeapi uses to populate its arrays, I'm at a loss why values available to the nodeapi function when invoked from one module seem to be unavailable when invoked from another.

I also tried running the dev 3.x version of the twitter module, but noticed that the nodeapi function was entirely absent from the twitter.module file, so I'm wondering whether it's being dropped, moved to another module, moved to an include file or just how the story is intended to play out???

#1

flacorps - June 29, 2009 - 01:37

I solved it ... the twitter.module twitter_nodeapi line 114 if statements incorrectly referenced "post" where they should have read "status" (correct: !empty($node->twitter['status'], not !empty($node->twitter['post']), so I was misled into setting the wrong, unused array in my mailhandler patch prior to the invocation of twitter_nodeapi. Changed "post" to "status" throughout and resolved that half of the problem.

The other half of the problem seemed to go away when I declared global $user at the beginning of twitter_nodeapi ... my watchdog was suddenly picking up both the username and password for the user's twitter account and the tweets started going through.

Anyone reading this should keep in mind that I'm a PHP novice, newbie, etc. and much more a hacker than a coder, so there are any number of things I could be communicating poorly at best and wrong about entirely at worst ... at any rate, my app is working as I expect and I can both post from e-mail with a tweet going immediately, and create or edit a blog entry on the site with the tweet going out correctly.

I also added " $node->twitter['account'] = array_pop(array_keys($twitter_accounts)); " from the module
drupalchix did over at http://drupal.org/node/379748 although I'm not sure whether it helped at all. Doesn't seem to have hurt anything...

#2

Summit - June 30, 2009 - 12:53

Subscribing, greetings, Martijn

#3

eaton - July 2, 2009 - 12:57

flacorps, that's not quite correct. $node->twitter['post'] is a boolean flag used to indicate that *the node should be annoucned to Twitter*, and status is the actual status message. 'status' always has a default message in it when the form is being filled out, thus isn't useful for checking

#4

flacorps - July 4, 2009 - 00:18

I'm confused (nothing new there). Is the flag set in line 91 (" $form['twitter']['post'] = array( ... ") ? I can't find any other spot in the code that might be a candidate.

Back to line 114, why isn't "!empty($node->twitter)" serving the boolean flag function, with "!empty($node->twitter[status])" being useful for making sure the user didn't entirely empty out the field (which would clearly lead to a pointless tweet--nevermind that the user could fill the field with garbage characters, which would be equally pointless)? It just makes more sense to me that !empty($node->twitter[post]) is some sort of leftover, but I will take the word of an expert, I swear I will.

I hate it when something I didn't know wasn't broken wouldn't work for me and it turns out the thing I did that seemed to fix it didn't really fix it. Makes it hard to go to sleep at night...

So what exactly did fix my problem?

On a (possibly) unrelated note, I did have to write a rule and action to make sure that posts of the type blog that were created from e-mail actually got published. Probably a stupid kludge I could have avoided with the right command dropped in here or there.

Oh well, gotta walk before I can run...

#5

kiamlaluno - July 8, 2009 - 05:37
Title:Twitter Module's nodeapi updates user's twitter status while user is logged on, but not when node is created remotely» Twitter module's nodeapi updates user's twitter status while user is logged on, but not when node is created remotely

$form['twitter']['post'] doesn't set the flag, but it declares the form field used to ask to the currently logged in user (if he has access to the page containing the form) the value to assign to the flag.

Before to be able to change the code of a module, you should learn more on how a Drupal module works, and what API Drupal exposes to third-party modules.

#6

radj - November 8, 2009 - 03:05

Subscribe. Interested in this feature. :)

 
 

Drupal is a registered trademark of Dries Buytaert.