The other day an idea popped in my head for a side project that would involve the Gmail API. Whenever this happens, I normally hit up the developer site, find a simple tutorial, and immediately get my hands dirty.
A quick search led me to this page. It’s called a “Quickstart: Run a Gmail App in Python.” Perfect. I’ll run this script and be on my way in no time. Well, not so fast.
This tutorial assumes I’m doing development on my local machine where it can pop open a web browser and authorize the API access. Most of the time I don’t operate that way – I use a remote Linux server of some kind.
To get this quick start guide working on a remote server:
- In the Google Developers Console, generate a client ID for a native application (this may work with other types of client IDs, but I know it works with a native one)
- Save the client_secret JSON to the script directory
- Add the ability to read command line arguments and call the function ‘tools.run_flow()’ instead of just ‘run’
- Run the script with “–noauth_local_webserver” as an argument
Now when you run the script, you’ll get a link to copy into any browser to authorize the access. Then, you’ll get an auth code to paste back into your script.
I’ve included both scripts so that you can compare easily. I hope this saves others from frustration and I also hope Google improves the tutorial.
This is something I created over a year ago and I’ve decided to share the code in case someone finds it useful.
- Click a node and drag
- Double-click to generate a node
- Click a node, hold down shift, then release over another node to connect
A super quick, super simple little example of how to get started with the AWS SDK2 for PHP. It connects to the S3 service with your credentials and checks to see if a file exists.
- Assuming you already have a LAMP setup, you may need to install php-pear:
sudo apt-get install php-pear
- Add the AWS channel and auto discover dependencies:
pear channel-discover pear.amazonwebservices.com
pear -D auto_discover=1 install pear.amazonwebservices.com/sdk
- Download the .phar file here and throw it on your server in this script’s directory (for this example).
- Replace the items in brackets and run the script. The [OBJECT KEY] is just the name of the file, so ‘mypicture.jpg’ in the root of the bucket would have the key ‘mypicture.jpg’.
$aws = Aws::factory(array(
'key' => '[KEY HERE]',
'secret' => '[SECRET HERE]'
$client = $aws->get('s3');
echo $client->doesObjectExist('[BUCKET NAME]', '[OBJECT KEY]');
You’ll get back the boolean response of that call (assuming it makes it that far without error). Refer to the API documentation for the other methods and their responses.
With an Arduino Ethernet, Processing, and a Kinect, I was able to easily create this little demo where hand movement can control a servo. This is just a tiny step in my master plan to create a robot clone so that I don’t have to leave my chair.
The following libraries and drivers made this work and also made it super easy for me to create it:
Daniel Shiffman’s Processing Kinect Library (he knows his stuff and has great examples on his site)
Arduino Ethernet UDP send / receive string
EMAX ES08A Servo
How it works:
- The Arduino Ethernet acquires an IP address and waits for UDP packets on a certain port.
- The machine with the Kinect sends packets to the Arduino that contain hand coordinate data.
- The Arduino then takes this data (an integer) and maps the range from 0 to 180 degrees.
- The mapped value is sent to the servo.
Uncaught TypeError: Cannot call method 'substr' of undefined
The transitions were working, but the previous image wasn’t ‘overlayed’ by the next image – it would just disappear and the new one would appear. It was almost like something else was there. Looking back at my ‘raw’ HTML code in the WordPress post, I had all three images in sequential order, but neatly aligned by pressing enter after each. What I didn’t know was that WordPress, even in HTML mode, was adding <br /> tags after I pressed enter, causing this problem.
Solution: Make the <img> tags back to back on the same line, thus removing the automatically generated <br /> tags.