Comments

Drave Robber’s picture

Assigned: Drave Robber » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.98 KB

Patch attached.

Notes:

  • I'm not using Twitter actively myself, so wording might need a review for compatibility with Twitter parlance of these days;
  • I'm used to specifying the callback explicitly in drush command definitions; if someone can explain why I shouldn't, I'm ready to repent :)
  • exceptions are not very willing to let themselves being catched :(
  • twitter_set_status() does not check whether the application has read access; if that's possible at all, probably it should, but this is outside of scope of this issue;
  • grabbing the first authenticated account in twitter_connect() could probably be a bit more robust, but this is outside of scope again. decided to check ourselves whether at least one account exists - see #3
Drave Robber’s picture

Status: Active » Needs work

To grab the first authenticated account, we need, well, at least one authenticated account to be added. This is something we can and should check for.

Drave Robber’s picture

Another attempt.
This time, we check ourselves whether at least one authenticated account exists and bail out if there's not.
Application having only read access can still result in mysterious errors.

webchick’s picture

I'm not exactly sure where to put this, but here's the set of instructions I needed to follow to get this working, which weren't really clear at the beginning:

0) Create an app at https://dev.twitter.com/apps. Yes, you need an entire "app" even though you're setting up a dumb site you're doing just purely to post to Twitter from Drush. ;)
1) Download Twitter and OAuth modules.
2) Enable the Twitter post module.
3) Go to admin/config/services/twitter/settings. Enter the "Consumer key" and "Consumer secret" values from https://dev.twitter.com/apps/YOUR-APP-ID/oauth
4) Take note of the "Callback URL" on that same page. Go to https://dev.twitter.com/apps/YOUR-APP-ID/settings and fill it in under "Callback URL." NOTE Drave Robber said that this should work from a localhost URL, but that was not the case for me. I had to put my site on a publicly-accessible URL for it to accept the value.
5) Also set your Application type access to "Read and write" on Twitter's app settings page.
6) Go back to Drupal and go to admin/config/services/twitter. Click the button there to authenticate.
7) This will redirect you to Twitter, click the "Authorize this app" button.
8) This will redirect you back to Drupal, and you should see your account details in the table there.

Now posting to Twitter from Drush should work. Hooray! :D

webchick’s picture

Specifically, it works like this. :)

$ drush tweet "This tweet was sent via Drush. Why? Because HELL YEAH, that's why! http://drupal.org/node/1890926 Thanks, Drave Robber! :D"
If you see nothing above this line, we successfully posted to Twitter.
webchick’s picture

One idea as a possible expansion to this would be to allow you to specify which account to post as. For example:

drush tweet --account=sparkdrupal "New stuff available for Spark! Even though my admin account is attached to 'webchick'."

That might work around the replication of twitter_connect() too, I'm not sure.

Drave Robber’s picture

Good point. It could work like drush cc - if called without an argument, it presents you a list of caches that can be cleared. Along the same lines, drush tweet 'some text' would present a list of available accounts.

That 'grab the first authenticated account' thing looked shoddy to me from the start.

webchick’s picture

Yeah, that's a great idea! Even better if it's smart enough to auto-select the first choice if there's only one available. :D Which I believe Drush handles already? (Maybe not.)

Drave Robber’s picture

Bigger and better version attached.

  • Takes text and screen_name as arguments, prompts to choose if the latter is not supplied.
  • Note: text comes first, so it's drush tweet "New stuff available for Spark!" sparkdrupal
  • Auto-selecting the only available account is not implemented, though - that might be a path to embarrassment in multisite environments (not that anyone maintains a pr0n store and Drupal shop on the same multisite, but anyway :)
  • interdiff.txt is #9 against #3.
Drave Robber’s picture

Need to make sure the length of the tweet does not exceed 140 chars, or it would crash with a giant sucking screeching sound.
Interdiff is #10 against #9.

On a side note, Twitter also does not allow posting the same text two times in a row; to check for that, however, we would need to refresh timeline before posting, and that would make the whole thing even slower than it already is.

juampynr’s picture

Thanks for the work you put into this. I apologize I could not give feedback earlier but I will look into it soon.

13rac1’s picture

FYI #10 applies cleanly.

jibran’s picture

Commit it please. It is a cool feature.

damienmckenna’s picture

Issue summary: View changes
Status: Needs review » Needs work

Triggering the testbot.

damienmckenna’s picture

Status: Needs work » Needs review

Triggering the testbot.

damienmckenna’s picture

damienmckenna’s picture

StatusFileSize
new3.11 KB

Some minor updates.

damienmckenna’s picture

Version: 7.x-5.x-dev » 7.x-6.x-dev
StatusFileSize
new3.1 KB

Ported to 7.x-6.x.

damienmckenna’s picture

Version: 7.x-6.x-dev » 6.x-5.x-dev
StatusFileSize
new3.11 KB

Ported to 6.x-5.x.

The last submitted patch, 19: twitter-n1890926-19-7.x-6.x.patch, failed testing.

damienmckenna’s picture

Status: Needs review » Fixed

Committed.

damienmckenna’s picture

Status: Fixed » Needs work

Whoops - just discovered a bug in the logic for selecting the account that's used to send the tweet. An update is on its way.

damienmckenna’s picture

Version: 6.x-5.x-dev » 7.x-5.x-dev
Status: Needs work » Needs review
StatusFileSize
new8.83 KB

This should resolve the problem.

damienmckenna’s picture

Version: 7.x-5.x-dev » 7.x-6.x-dev
StatusFileSize
new8.83 KB

Ported to 7.x-6.x.

damienmckenna’s picture

StatusFileSize
new6.51 KB

Ported to 6.x-5.x.

The last submitted patch, 27: twitter-n1890926-27-7.x-6.x.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 28: twitter-n1890926-28-6.x-5.x.patch, failed testing.

  • DamienMcKenna committed 3ca51f5 on 7.x-5.x
    Issue #1890926 by DamienMcKenna: Fixes to the Drush 'tweet' command.
    

  • DamienMcKenna committed e81094b on
    Issue #1890926 by DamienMcKenna: Fixes to the Drush 'tweet' command.
    
damienmckenna’s picture

Status: Needs work » Fixed

Committed.

Status: Fixed » Closed (fixed)

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