I was wondering how you would tweet pictures on the Pi through Python. I can't use Twython for a reason that is too long to go into.
Thanks.
-
- Posts: 58
- Joined: Wed Aug 14, 2013 7:16 am
- DougieLawson
- Posts: 42313
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Tweeting Pictures
You can do it with Tweepy http://github.com/tweepy
Parm#1 is the image filename
Parm#2 is the text for the status.
https://twitter.com/IMSlights/status/428334873859067905
Code: Select all
#!/usr/bin/python
import os
import sys
import tweepy
Ckey = 'Consumer_Key_here'
Csec = 'Consumer_Secret_here'
Akey = 'Application_Key_here'
Asec = 'Application_Secret_here'
auth = tweepy.OAuthHandler(Ckey, Csec)
auth.set_access_token(Akey, Asec)
twapi = tweepy.API(auth)
fn = os.path.abspath(sys.argv[1])
status = sys.argv[2]
twapi.update_with_media(fn, status=status)
Parm#2 is the text for the status.
https://twitter.com/IMSlights/status/428334873859067905
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
Re: Tweeting Pictures
Just had a play with Dougie's code. Thanks for posting that 
Two things to note.
1/ I had tweepy 2.1 installed and it doesn't support update_with_media()
Couldn't get the booger working until I updated tweepy (which I only installed in September 2013) to 2.2. Then it worked fine.
2/ Your text for your status update should be in quotes when you enter it on the command line. Otherwise it stops at the first space.
Other than that, excellent tip there Dougie. The documentation for tweepy is pretty out of date, which makes life difficult for beginners (and a lot of other people too).

Two things to note.
1/ I had tweepy 2.1 installed and it doesn't support update_with_media()
Couldn't get the booger working until I updated tweepy (which I only installed in September 2013) to 2.2. Then it worked fine.

2/ Your text for your status update should be in quotes when you enter it on the command line. Otherwise it stops at the first space.
Other than that, excellent tip there Dougie. The documentation for tweepy is pretty out of date, which makes life difficult for beginners (and a lot of other people too).
Alex Eames RasPi.TV, RasP.iO
- DougieLawson
- Posts: 42313
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Tweeting Pictures
I took ages finding a working version. V2.2 was the third one I tried. There was a old fork of tweepy code that didn't work with https.alexeames wrote: Couldn't get the booger working until I updated tweepy (which I only installed in September 2013) to 2.2. Then it worked fine.
Most of my machine generated tweets come from a Perl program use Net::Twitter. I'm not a big fan of python. I prefer the write once, debug never feature of Perl to the semantic white space feature of python.
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
Re: Tweeting Pictures
I used to do back-end stuff for websites in PERL. I've got a shopping cart and banner ad server I wrote 10 years ago still working.DougieLawson wrote:Most of my machine generated tweets come from a Perl program use Net::Twitter. I'm not a big fan of python. I prefer the write once, debug never feature of Perl to the semantic white space feature of python.
/*I learnt REXX during my pre-Uni year at IBM*/
/*The Systems Product Interpreter*/
I do like Python though - very much. Although I was happy with PERL's {}
Alex Eames RasPi.TV, RasP.iO