The latest update makes it so I can't post to Twitter. Rolling back to 5.5 works fine. I've tried clearing caches and removing/re-enabling the main (and only) Twitter account that this module is using to post.

exception 'TwitterException' with message 'Forbidden' in /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/sites/all/modules/contrib/twitter/twitter.lib.php:135 Stack trace: #0 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/sites/all/modules/contrib/twitter/twitter.lib.php(100): Twitter->request('https://api.twi...', Array, 'POST') #1 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/sites/all/modules/contrib/twitter/twitter.lib.php(1209): Twitter->auth_request('https://api.twi...', Array, 'POST') #2 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/sites/all/modules/contrib/twitter/twitter.lib.php(339): Twitter->call('statuses/update', Array, 'POST') #3 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/sites/all/modules/contrib/twitter/twitter.inc(178): Twitter->statuses_update('New Literature:...') #4 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/sites/all/modules/contrib/twitter/twitter_post/twitter_post.module(98): twitter_set_status(Object(TwitterUser), 'New Literature:...') #5 [internal function]: twitter_post_node_insert(Object(stdClass)) #6 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/includes/module.inc(857): call_user_func_array('twitter_post_no...', Array) #7 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/modules/node/node.module(1133): module_invoke_all('node_insert', Object(stdClass)) #8 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/modules/node/node.pages.inc(413): node_save(Object(stdClass)) #9 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/includes/form.inc(1464): node_form_submit(Array, Array) #10 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/includes/form.inc(860): form_execute_handlers('submit', Array, Array) #11 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/includes/form.inc(374): drupal_process_form('literature_node...', Array, Array) #12 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/includes/form.inc(131): drupal_build_form('literature_node...', Array) #13 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/modules/node/node.pages.inc(73): drupal_get_form('literature_node...', Object(stdClass)) #14 [internal function]: node_add('literature') #15 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/includes/menu.inc(517): call_user_func_array('node_add', Array) #16 /srv/bindings/8d4d60477e04487289b3630b65e909e7/code/index.php(21): menu_execute_active_handler() #17 {main}

Comments

jkew’s picture

I am having the same issue. However, I uninstalled v5.6 and installed v5.5 and have the same error message (in the log) coming up. Any help would be appreciated. Thanks.

juampynr’s picture

The "Forbidden" error happens when you try to post with a non-authenticated Twitter account. Please review the updated installation settings at http://drupal.org/node/1346824.

nwehner’s picture

It's definitely authenticated. I even tried removing that account, clearing caches, and authenticating a separate (my personal) Twitter account as opposed to my site's.

Since the re-install of version 5.5 I've had the main authenticated account work just fine on most content types, but it pulls up the Forbidden error message on blogs. Way weird.

Dave Hirschman’s picture

This problem occurs for me when the title of the node being posted to twitter is too long. Node titles can be up to 255 characters, but the twitter status must be less than 140 characters. Function twitter_post_nodeapi in file twitter_post/twitter_post.module (either 7.x or 6.x) does not check to see if the complete status message (with all tokens) is less than 140 characters. I believe that Twitter throws the FORBIDDEN error when the tweet is too long. I tested this idea by changing

$replacements = array(
          '!title' => $node->title,

to

$max_title = 90;
$replacements = array(
          '!title' => truncate_utf8($node->title, $max_title, false, true),

and that eliminates the problem.

nwehner’s picture

Status: Active » Patch (to be ported)
StatusFileSize
new857 bytes

Dave certainly seems to have identified the problem - thanks, Dave!

I put his changes in a patch. It fixes all my problems.

dooug’s picture

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

Tested patch & confirmed it works on latest 7.x-5.x-dev. Thanks!

dooug’s picture

Title: Update breaks posting: exception 'TwitterException' with message 'Forbidden' » Update with long title breaks posting: exception 'TwitterException' with message 'Forbidden'
dddave’s picture

Status: Patch (to be ported) » Reviewed & tested by the community

Shouldn't this get into a branch before porting?
Secondly I think there is a UX problem that at least needs to be documented for endusers: A tweet might be to long depending on the title (+short url). But this is a general concern.

mastoll’s picture

A tale of two versions and two features:
I applied patch in #5 to version 7.x-5.x-dev and still received the TwitterException error, but hashtag converter works fine.
Installed version 7.x-5.8 and the patch worked, no TwitterException, but now I get the hashtag converter URL problem from Twitter #hashtag converter returns wrong address.

Edit:
Patch did NOT work on 7.x-5.x-dev for me, but DID work on the 7.x-5.8 production version.
Per discussion in #2018509: New Twitter API, I adjusted the Twitter settings and resolved the hashtag address issue.

tanc’s picture

Patch re-rolled with correct p1 format. Also confirmed this fixes the issue with tweets with very long titles now able to be posted.

marcoka’s picture

i also have this issue. my stuff is posted but i also get the error in the log.

dddave’s picture

How about testing the patch then @ marcoka?

marcoka’s picture

lol i am am currently doing that :)

marcoka’s picture

reporting back. patch works here and fixes that error. thank you.

damienmckenna’s picture

Status: Reviewed & tested by the community » Needs review

Triggering the testbot.

The last submitted patch, 5: twitter_truncate-node-title-90-characters-1943398.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 10: twitter-truncate_title_90_characters-1943398-10.patch, failed testing.

damienmckenna’s picture

Status: Needs work » Needs review
damienmckenna’s picture

StatusFileSize
new1.61 KB

Strictly, speaking, the maximum length of a tweet that contains a URL is 117 with the tco URL holding the rest. This leads to this patch which truncates the string to 117 chars instead of 90.

damienmckenna’s picture

Version: 7.x-5.x-dev » 6.x-5.x-dev
StatusFileSize
new1.63 KB

Ported to the 6.x-5.x branch.

damienmckenna’s picture

Because the 7.x-6.x branch uses actual tokens, it'd be harder to limit those strings so just update the description for the status field.

Status: Needs review » Needs work

The last submitted patch, 22: twitter-n1943398-21-7.x-6.x.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 22: twitter-n1943398-21-7.x-6.x.patch, failed testing.

  • DamienMcKenna committed 8e0dfd7 on 6.x-5.x authored by nwehner
    Issue #1943398 by nwehner, tanc, DamienMcKenna: Truncate !title token to...
damienmckenna’s picture

I've committed the change to the 6.x-5.x and 7.x-5.x branches, but the 7.x-6.x patch is failing because of a testbot problem: #2548073: Testbot is checking out old version of Twitter 7.x-6.x branch

  • DamienMcKenna committed 098bb03 on 7.x-5.x authored by nwehner
    Issue #1943398 by nwehner, tanc, DamienMcKenna: Truncate !title token to...
joelpittet’s picture

@damienmckenna To make testbot smarten up I had to tag a new release (beta in my case for commerce discount)

https://www.drupal.org/node/2490991#comment-10159828

damienmckenna’s picture

Status: Needs work » Fixed

I've committed the 7.x-6.x change, will deal with testbot separately.

damienmckenna’s picture

@joelpittet: Thanks for the tip, I'll take care of this soon.

marcoka’s picture

thank you drupal ninjas :)

Status: Fixed » Closed (fixed)

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

Rob T’s picture

I seem to be experiencing this issue with 7.x-6.2 (Oct 5 2015), though I see Damien mention the commit to 7.x-6.x (comment #30, Aug 8 2015).

I have been documenting my observations in a different issue thread that initially suspected the error occurring when attempting to post duplicate messages (which I am not attempting), but my observatins are that the error occurs when the message length via my [node:title] is lengthier than the messages I am able to post to Twitter successfully.

https://www.drupal.org/node/2038155