howdy,

had twitter working fine on individual accounts. i decided to go with the sitewide account. i'm also using workflows so i setup an action and a trigger.

i also patched this 2.4 version because i was getting the WSOD.

everything is fixed. successfully posts to twitter.

the only problem is that it just prints the literal token - %title.

i tried it with !title !url which is in the default single user setup and that's no good either. whatever i put in the messagefield, what gets posted to twitter is literally what's in the field.

i've got the messagefield in actions set to plain text.

any ideas?

Comments

nathanmcginty’s picture

UPDATE -

Think it has something to do with my workflow settings. It passes the %site_name (whatever the actual code of that token is, don't have it right in front of me) so that it shows up in twitter as a url.

so i guess it's not getting the %url or %title from any of the actions. i moved the twitter post to last, but that didn't seem to make any difference.

here's the actions order:

MOVE POST TO NEW STATE
PUBLISH POST
PROMOTE POST TO FRONT PAGE
SAVE POST
SEND MESSAGE TO TWITTER

Thanks!

nathanmcginty’s picture

UPDATE, Part 2

Yeah, it's got to be something with the way Twitter is dealing with the tokens in Actions. I just sent a twitter message using all the variable it says are available in the Actions:

%site_name %username %node_url %node_type %title %teaser %body

What posted to Twitter was:

www.freedomhaters.org %node_url %node_type %title %teaser %body

%site_name was passed fine and showed up as a link. everything else was plain text. i guess it's not getting the variable from the node?

I added a "Send Tokenized Email" action right before the Twitter. That gets all the variable fine.

Sinan Erdem’s picture

I also have the same problem.

I am using Rules module, and even if I use %title, %node_url or anything apart from %site_name, it just prints as it is...

But where is "Send Tokenized Email" ? I cannot seem to find that action..

profjk’s picture

**subscribing**

pyxio’s picture

I'm having the same problem using Rules triggers.

pyxio’s picture

Is there any help for this on the way? It seems like a rather significant bug, isn't it?

Sinan Erdem’s picture

Title: !url being posted » !url being posted without tokens replaced
Category: support » bug
pyxio’s picture

Is this issue dead?

pyxio’s picture

Since this is apparently not going to be resolved anytime soon, is it something i can PAY to have done? The twitter automation with rules module is very important. Please let me know. Thank you. K

kmadel’s picture

Basically, for 'Workflow' the context of the action comes across as 'workflow' and there is not case in the context switch for this. I don't have time to role a patch right now, but basically in the context of workflow, the node object must be retrieved from the $context and is not the $object being passed into the action.

So basically, the context switch is defaulting and trying to use: $node = $object;

If you added (for workflow) the following switch case, it will work as a workflow action (twitter_actions.module):
case 'workflow':
// Because this is not an action of type 'node' the node
// will not be passed as $object, but it will still be available
// in $context.
//$node = $object;
$node = $context['node'];
watchdog('twitter_actions', "context hook is: !hook ", array('!hook' => $context['hook']));
watchdog('twitter_actions', "Node with !title, sent as twitter status.", array('!title' => $node->title));
break;

eaton’s picture

You are, indeed, correct. The 'Post to twitter' action was originally intended as a general utility action, and doesn't have provisions for pulling a lot of context straight from a node. I'll be looking into it as I have time, but at least for the time being it isn't something that's being used by any of our clients/my sites/etc and it's hard to carve out the time for it.

Patches to twitter_actions readily accepted, though -- I haven't had time to dig in very deep.

mountaineer’s picture

Curious if there's anything new on this? I'm trying to unwind the use of Rules, Twitter, Twitter Action, Pathauto, Shorten, etc., etc.

I started out with a twitter action using a [node:url] token in the Twitter Action message field and in general, the [] style of tokens instead of the %token style that was suggested in the text below the field. Unfortunately, the [node:url] shortened the /node/number style rather than the aliased version from pathauto.

Which token style should we be using for Twitter actions? Only the %site_name worked out of the ones listed, so I'm not sure what the point of those is, why even have them if the [] style is there too?

jeni_dc’s picture

I was having some trouble with this, too, in trying to create an automatic post to twitter for a specific content type with a rule. I wanted to automatically post to twitter every time a certain node type was published using the format of: Node Title tinyurl. So if my post was called "This is a test post" the resulting tweet would read:

This is a test post http://tinyurl.com/xxxxxx

I looked into the twitter module to see how it was generating the tinyurls, then was able to get around this by using php code in the "Message" part of the rule like so:

<?php print check_plain($node->title) . ' ';
$response = drupal_http_request("http://tinyurl.com/api-create.php?url=http://www.example.com/" . $node->path);
if ($response->code == 200) {
return $response->data;
}
?>

Replace http://www.example.com/ in the above example with your url and it should work, complete with path alias, too!

DC

Michsk’s picture

you should create a else which prints the url witouth tinyurl.

jeni_dc’s picture

Yeah, that's certainly a good idea! So here's the updated code for that:

<?php print check_plain($node->title) . ' ';
$response = drupal_http_request("http://tinyurl.com/api-create.php?url=http://www.example.com/" . $node->path);
if ($response->code == 200) {
return $response->data;
}
else {
return 'http://www.example.com/' . $node->path;
}
?>

I did run into a MAJOR problem overall though with using that snippet. I was testing this using nodes that were to be submitted by anonymous users, and therefore unpublished by default. The admins were to then publish them after approval. So for that it was working great, but. . .

I then was testing similar functionality for the same site with nodes being created by administrators and being published straight away, and it seems that $node->path isn't available at that point so the URL in the resulting tweet was only http://www.example.com . So for now I've ended up using:

<?php print check_plain($node->title) . ' ';
$response = drupal_http_request("http://tinyurl.com/api-create.php?url=http://www.example.com/node/" . $node->nid);
if ($response->code == 200) {
return $response->data;
}
else {
return 'http://www.example.com/node/' . $node->nid;
}
?>

Sadly that won't return the SEO pathauto URLs, but at least it's getting people to the right place, especially with Global Redirect installed.

DC

nplus1’s picture

unfortunately, this does not work for me. hence i used:

 $response = drupal_http_request("http://tinyurl.com/api-create.php?url=http://www.xyz.com/node/" . $node->nid);
if ($response->code == 200) {echo $response->data;}
else {echo 'http://www.xyz.com/node/' . $node->nid;}
steinmb’s picture

Version: 6.x-2.4 » 7.x-3.x-dev
Component: Code » Twitter Actions

Pls. close if the old issue is fixed.

steinmb’s picture

Status: Active » Closed (duplicate)