Hi there. I am trying to integrate the twitter module and mailhandler.
I've looked at the code of the twitter_post.module and have found that there exists a node action for node->twitter and $node->twitter['post']. Based on this, I've included in the mailhandler command twitter: 1 to allow for automatic posting into twitter. This seems to have worked since I get the message 'Successfully posted to Twitter' after retrieving mail - which indicates to me that the twitter module is happy (for a look under the hood see code at the end of this post). Further, the twitter module functions fine when content is submitted via the website. This leads me to beleive that there is some issue with the mailhandler commands that I am not understanding since no content is posted to twitter when submitted via email. Is there something that I am missing as far as mailhandler commands is concerned? Is this a mailhandler bug?
function twitter_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
global $user;
switch ($op) {
case 'insert':
case 'update':
if (!empty($node->status) && !empty($node->twitter) && !empty($node->twitter['post'])) {
module_load_include('inc', 'twitter');
$twitter_account = twitter_account_load($node->twitter['account']);
$replacements = array('!title' => $node->title,
'!url' => url('node/'. $node->nid, array('absolute' => TRUE, 'alias' => TRUE)),
'!url-alias' => url('node/'. $node->nid, array('absolute' => TRUE)),
'!user' => $node->name);
// Only generate the shortened URL if it's going to be used. No sense
// burning through TinyURLs without a good reason.
if (strstr($node->twitter['status'], '!tinyurl') !== FALSE) {
$replacements['!tinyurl'] = twitter_shorten_url(url('node/'. $node->nid, array('absolute' => TRUE)));
}
$status = strtr($node->twitter['status'], $replacements);
try {
$result = twitter_set_status($twitter_account, $status);
drupal_set_message(t('Successfully posted to Twitter'));
}
catch (TwitterException $e) {
drupal_set_message(t('An error occurred when posting to twitter: %code %error',
array('%code' => $result->code, '%error' => $result->error)), 'warning');
}
}
break;
}
}
Comments
Comment #1
Bèrto ëd Sèra commentedsubscribe
Comment #2
benklocek commentedSubscribe
Comment #3
danepowell commentedWhat are your other mappings? Sounds like the body (origbody) isn't being mapped to the node body.
Comment #4
timaholt commentedsubscribe
Comment #5
danepowell commentedNevermind- the issue is almost certainly that FeedsNodeProcessor doesn't provide a mapping to the Twitter field. The Twitter module will need to implement a hook to add "Twitter" as a mapping target for FeedsNodeProcessor. There's nothing that Mailhandler needs to do to support this, as near as I can tell.