1. Authenticated successfully
2. Created an action to post tweeter message for specific nodes when they are publish
3. Unpublish and then publush node => received "Successfully posted to Twitter" message
4. Nothing on twitter and log contains error message:

exception 'TwitterException' with message 'Unauthorized' in /path/sites/all/modules/contrib/twitter/twitter.lib.php:151 Stack trace: #0 /path/sites/all/modules/contrib/twitter/twitter.lib.php(116): Twitter->request('https://api.twi...', Array, 'POST') #1 /path/sites/all/modules/contrib/twitter/twitter.lib.php(1225): Twitter->auth_request('https://api.twi...', Array, 'POST') #2 /path/sites/all/modules/contrib/twitter/twitter.lib.php(355): Twitter->call('statuses/update', Array, 'POST') #3 /path/sites/all/modules/contrib/twitter/twitter.inc(180): Twitter->statuses_update('
What gets we...') #4 /path/sites/all/modules/contrib/twitter/twitter_actions/twitter_actions.rules.inc(68): twitter_set_status(Object(TwitterUser), '

What gets we...') #5 [internal function]: twitter_actions_set_status('

What gets we...', '[current user]', Array, Object(RulesState), Object(RulesAction), 'execute') #6 /path/sites/all/modules/contrib/rules/includes/faces.inc(123): call_user_func_array('twitter_actions...', Array) #7 /path/sites/all/modules/contrib/rules/includes/rules.core.inc(297): FacesExtendable->__call('execute', Array) #8 /path/sites/all/modules/contrib/rules/includes/rules.plugins.inc(20): RulesExtendable->__call('execute', Array) #9 /path/sites/all/modules/contrib/rules/includes/rules.core.inc(1570): RulesAction->executeCallback(Array, Object(RulesState)) #10 /path/sites/all/modules/contrib/rules/includes/rules.core.inc(2215): RulesAbstractPlugin->evaluate(Object(RulesState)) #11 /path/sites/all/modules/contrib/rules/includes/rules.plugins.inc(216): RulesActionContainer->evaluate(Object(RulesState)) #12 /path/sites/all/modules/contrib/rules/includes/rules.plugins.inc(392): Rule->evaluate(Object(RulesState)) #13 /path/sites/all/modules/contrib/rules/includes/rules.core.inc(2215): RulesReactionRule->evaluate(Object(RulesState)) #14 /path/sites/all/modules/contrib/rules/includes/rules.plugins.inc(695): RulesActionContainer->evaluate(Object(RulesState)) #15 /path/sites/all/modules/contrib/rules/rules.module(833): RulesEventSet->executeByArgs(Array) #16 /path/sites/all/modules/contrib/rules/modules/events.inc(77): rules_invoke_event('node_update', Object(stdClass)) #17 [internal function]: rules_entity_update(Object(stdClass), 'node') #18 /path/includes/module.inc(895): call_user_func_array('rules_entity_up...', Array) #19 /path/modules/node/node.module(1180): module_invoke_all('entity_update', Object(stdClass), 'node') #20 /path/modules/node/node.admin.inc(327): node_save(Object(stdClass)) #21 /path/modules/node/node.admin.inc(301): _node_mass_update_helper('13', Array) #22 [internal function]: node_mass_update(Array, Array) #23 /path/modules/node/node.admin.inc(640): call_user_func_array('node_mass_updat...', Array) #24 /path/includes/form.inc(1465): node_admin_nodes_submit(Array, Array) #25 /path/includes/form.inc(861): form_execute_handlers('submit', Array, Array) #26 /path/includes/form.inc(374): drupal_process_form('node_admin_cont...', Array, Array) #27 /path/includes/form.inc(131): drupal_build_form('node_admin_cont...', Array) #28 [internal function]: drupal_get_form('node_admin_cont...') #29 /path/includes/menu.inc(517): call_user_func_array('drupal_get_form', Array) #30 /path/index.php(21): menu_execute_active_handler() #31 {main}

Also tried to update Twitter settings:
- Added read and write
- Added trailing slash to Callback URL

Comments

VladimirAus’s picture

Issue summary: View changes

Update with Twitter settings

psacc’s picture

I dug onto this one and I think the code handling the case of unsuccesfull status update has a bug:

http://drupalcode.org/project/twitter.git/blob/1b91dfa76f0f60c788ed5226d...

  57 function twitter_actions_set_status($message, $sender) {
  58   $twitter_uid = _twitter_actions_get_twitter_id($sender);
  59   if (!isset($twitter_uid)) {
  60     // No Twitter authenticated account found.
  61     return;
  62   }
  63 
  64   // Send tweet.
  65   module_load_include('inc', 'twitter');
  66   $twitter_account = twitter_account_load($twitter_uid);
  67   try {
  68     twitter_set_status($twitter_account, $message);
  69     drupal_set_message(t('Successfully posted to Twitter'));
  70   }
  71   catch (TwitterException $e) {
  72     drupal_set_message(t('An error occurred when posting to Twitter: @message',
  73                          array('@message' => $e->getMessage())), 'warning');
  74   }
  75 }

this code expects an exception, but receives the value created by this code:
http://drupalcode.org/project/twitter.git/blob/1b91dfa76f0f60c788ed5226d...

1221   public function call($path, $params = array(), $method = 'GET') {
1222     $url = $this->create_url($path);
1223 
1224     try {
1225       $response = $this->auth_request($url, $params, $method);
1226     }
1227     catch (TwitterException $e) {
1228       watchdog('twitter', '!message', array('!message' => $e->__toString()), WATCHDOG_ERROR);
1229       return FALSE;
1230     }
1231 
1232     if (!$response) {
1233       return FALSE;
1234     }
1235 
1236     return $this->parse_response($response);
1237   }

used by this (as pointed by the stacktrace):

 343   /**
 344    * Updates the authenticating user's current status, also known as tweeting.
 345    *
 346    * @param string $status
 347    *   The text of the status update (the tweet).
 348    * @param array $params
 349    *   an array of parameters.
 350    *
 351    * @see https://dev.twitter.com/docs/api/1.1/post/statuses/update
 352    */
 353   public function statuses_update($status, $params = array()) {
 354     $params['status'] = $status;
 355     $values = $this->call('statuses/update', $params, 'POST');
 356     return new TwitterStatus($values);
 357   }

Not sure how this can affect other call paths, but unsuccessful status publication to twitter triggered by rule action is actually broken.

psacc’s picture

Title: Can not post to twitter » Failed status updates triggered by rules actions show the success message
Priority: Major » Critical

added clarification to the title
raised priority as the issue falsely reports the action as succesful

juampynr’s picture

Status: Active » Postponed (maintainer needs more info)

2. Created an action to post tweeter message for specific nodes when they are publish

Where did you find that event? When I create a rule I only see the following events related with nodes:

  • After deleting content
  • After saving new content
  • After updating existing content
  • Before saving content
  • Content is viewed
juampynr’s picture

Status: Postponed (maintainer needs more info) » Fixed

Adjusted how the response is treated when there is an error. As @psacc said, no Exception is bubbled up since the call() method catches it. I have adjusted it so now it rethrows the Exception and each scenario can decide on what to do.

http://drupalcode.org/project/twitter.git/commit/1e90e0b
http://drupalcode.org/project/twitter.git/commit/31a614e

As for the Forbidden message, note that Twitter won't let you post the same tweet message twice. Make sure that your rule's pattern produces a unique tweet message.

juampynr’s picture

Version: 7.x-5.8 » 7.x-5.x-dev

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.