Tweet from Tasker

924 views
Skip to first unread message

bdanders

unread,
Feb 4, 2013, 12:41:27 PM2/4/13
to tas...@googlegroups.com
Has anyone found a way to post to Twitter directly from Tasker without any extra intervention? I've looked for a plugin without any success. I've looked into possibly using a Python script with SL4A, but unless I can find a ready made solution that's probably over my head.

TomL

unread,
Feb 4, 2013, 12:56:47 PM2/4/13
to tas...@googlegroups.com
Aren't tweets sent using SMS?  So, just have Tasker sent the SMS.

Tom

bdanders

unread,
Feb 4, 2013, 12:59:17 PM2/4/13
to tas...@googlegroups.com
Although that is a solution, I'm trying to do this to a secondary account that isn't associated with my phone number. Thanks for the suggestion though.

I'm currently trying to see if I can wade through this: http://giantmetalrobot.blogspot.com/2011/05/android-tweeting-with-python-tweepy-and.html

Matt R

unread,
Feb 4, 2013, 1:08:37 PM2/4/13
to tas...@googlegroups.com

bdanders

unread,
Feb 4, 2013, 1:10:34 PM2/4/13
to tas...@googlegroups.com
I played with that a bit, but couldn't figure out how to get around the required OAuth authorization.

bdanders

unread,
Feb 4, 2013, 1:45:33 PM2/4/13
to tas...@googlegroups.com
Success! I have SL4A tweeting automagically using the directions from here: http://giantmetalrobot.blogspot.com/2011/05/android-tweeting-with-python-tweepy-and.html

Should be a fairly simple step to add tasker variables and automate further.

bdanders

unread,
Feb 4, 2013, 2:55:01 PM2/4/13
to tas...@googlegroups.com
For the sake of anybody that might find this in a search (and so I can remember later) here is what I did.

All of this is borrowed from here:
http://giantmetalrobot.blogspot.com/2011/05/android-tweeting-with-python-tweepy-and.html

and here:
http://talkfast.org/2010/05/31/twitter-from-the-command-line-in-python-using-oauth/

and here:
https://github.com/tweepy/tweepy

As a warning, I am not a Python programmer. I probably can't help you figure out why it doesn't work for you.
First thing to do is go to your Twitter account and create an application (https://dev.twitter.com/apps). Make sure your application has read AND write access. From there you can get the required Consumer key and Consumer secret. You can also create the Access token and Access secret directly from this page, thereby skipping step 3 in the instructions linked. Then you need to create a subfolder on your phone called 'tweepy' in your sl4a directory into which you copy all of the .py files from the tweepy library (https://github.com/tweepy/tweepy/archive/master.zip). Then create your sl4a script like so:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

#!/usr/bin/env python

import sys
import tweepy
import android
droid=android.Android()

CONSUMER_KEY = 'paste your Consumer Key here'
CONSUMER_SECRET = 'paste your Consumer Secret here'
ACCESS_KEY = 'paste your Access Key here'
ACCESS_SECRET = 'paste your Access Secret here'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

tweet = droid.dialogGetInput('Twitter', 'Type your tweet here :').result
api.update_status(tweet)

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

Place all 4 required keys and secrets where indicated in the script. When it is run, the script should pop up a little dialog that prompts you to enter your tweet, then it sends it on its way.

If you want to have tasker automatically assign the text of the tweet then replace this line:
tweet = droid.dialogGetInput('Twitter', 'Type your tweet here :').result
with this:
tweet = droid.getIntent().result[u'extras'][u'%tweet']
and when you run the script, pass a variable named '%tweet' along with it.

I hope this helps someone else. I'm a little surprised there isn't already such a plugin.  Seems like it should be a pretty easy task for someone that knows what they're doing.

joaomgcd

unread,
Feb 17, 2013, 4:32:10 PM2/17/13
to tas...@googlegroups.com
Or you could use AutoRemote and Zapier to do this the easy way. :)
Message has been deleted

Tim Walls

unread,
Jun 16, 2014, 9:17:03 PM6/16/14
to tas...@googlegroups.com
Tried getting this to work and took me a few days but finally, these are the steps I used;

1. Install SL4A. https://code.google.com/p/android-scripting/downloads/detail?name=sl4a_r6.apk (you will need to enable unknown sources in the Android settings)
4. Open Python for Android, choose Install, then click Import Modules and choose Tweepy 2.3.
5. Goto https://apps.twitter.com/ and create an application.
6. Set application permissions to "Read, write, and direct messages".
7. Generate Access Token under the APIS menu.
8. Open SL4A and choose Add, Python.
9. Name the file tweet.py and paste the following script (without the +-+-+-+) filling in your API Key, API Secret, Access Token and Access Token Secret from Twitter Application page;
10. Create a task in tasker to set variable %tweet to what you want to tweet then Misc/Run Script and select tweep.py, in the pass variables section type %tweet.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

#!/usr/bin/env python

import sys
import tweepy
import android
droid=android.Android()

API_KEY = 'paste your API Key here'
API_SECRET = 'paste your API Secret here'
ACCESS_TOKEN = 'paste your Access Token here'
ACCESS_TOKEN_SECRET = 'paste your Access Token Secret here'

auth = tweepy.OAuthHandler(API_KEY, API_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth, secure=True)


tweet = droid.getIntent().result[u'extras'][u'%tweet']
api.update_status(tweet)

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

Marta Hintz

unread,
Jun 16, 2014, 11:34:06 PM6/16/14
to tas...@googlegroups.com
Thank you for the great info

har...@harshadsharma.com

unread,
Jun 18, 2014, 4:37:03 AM6/18/14
to tas...@googlegroups.com
Ran into this discussion, realized it's a little too much work (though I'm comfortable with writing code)

So I figured a simpler way to do this (It's 2014, c'mon!) - use Zapier. Free account is good enough. I've shared the recipe to make it trivial to get started: https://zapier.com/zapbook/webhook/twitter/34933/web-hook-catch-hook-to-twitter-create-tweet/

You'll get a webhook url from Zapier, write it down/copy it for the next step.

From within Tasker, create a task to tweet as shown here: https://www.dropbox.com/s/y1vli3nmg4x2btv/2014-06-18%2014.02.01.png

Finally, whenever you need to send a tweet, set the variable %Tweet and call this task next.

Hope this helps.

Gabriel Ionita

unread,
Dec 24, 2014, 5:46:33 PM12/24/14
to tas...@googlegroups.com
It works for me. Looking now to find how can I send a Tweet with photo.
BR.
Reply all
Reply to author
Forward
0 new messages