I’ve been using this setup for some time now and it’s so insanely useful it’d be a shame if I didn’t share it. (Note: this isn’t new.) Basically, I use Git for my source control and Dropbox as my online repository—and it’s a snap to set up.
- Create a directory in your Dropbox folder for your projects. Mine’s called “Projects.”
- Open up a terminal and go to the directory of the project you’d like to host on Dropbox.
- In the terminal type:
git clone --bare . ~/Dropbox/[projects folder]/[project name].git
- Then type:
git remote add [project name] ~/Dropbox/[projects folder]/[project name].git
That’s it! Now after every local commit, you can push your changes to Dropbox by doing
git push [project name] master.
When I want to work on a project on my laptop, I run
git clone ~/Dropbox/[projects folder]/[project name].git once to grab the initial code and
git pull origin master everytime I want to pull new changes in.
I spent part of last week working on an entry for the Boxee/Twilio developer contest. A few days before the deadline, I decided it’d be really slick if I added Netflix into the mix, so I started digging through the documentation. I think Twilio’s simple API and awesome debugging tools spoiled me because figuring out Netflix’s API was a pain. A lot of this had to do with there not being a really good PHP library to take care of authorization and making signed calls to the API. I went with OAuthSimple and ran into a lot of “invalid signature” errors and other little gotchas along the way. Hopefully, this write-up and sample code will save you guys some time.
Before You Begin
In order to get started, you’ll need to sign up for a Netflix developer account and apply for an API key. (This is separate from your normal Netflix account.) After you’ve been approved (as far as I can tell, approval is instant), you’ll receive a “key” and a “shared secret.” From here on out, we’ll call them the “consumer key” and “consumer secret.”
Write both of those down, because we’ll be using them often. You’ll also want to get yourself a copy of the OAuthSimple library.
Netflix uses OAuth, so you’ll need to have users authorize your application before you can work with their data. In order to do this, we’ll create a link that takes them to the authorization page.
If all goes well and the user authorizes the application, Netflix will call the page you specified in the link above and pass it the user’s OAuth token. You can then exchange that temporary token for a permanent OAuth token, OAuth token secret, and user ID. You’ll want to save this information in your database (or however you’re storing data) since you’ll be using it to make calls to the Netflix API.
Making Calls to the API
Now that the user has authorized your application, you’re ready to actually start working with the API . The API is REST based, so it’s as simple as specifying a URL, passing in the proper parameters, and parsing the data returned.
For example, here’s how to get a list of the movies in the user’s Instant Watch queue:
Adding movies to a user’s queue is similar—just specify the URL (http://api.netflix.com/users/[netflix_user_id]/queues/instant/disc), pass in the proper parameters, and parse the data returned. Also, remember that when writing data, set cURL to POST the data (
curl_setopt($curl, CURLOPT_POST, true) and
curl_setopt($curl, CURLOPT_POSTFIELDS, [parameters to pass])) and set the action to POST in the OAuthSimple library (
Check out Netflix’s documentation for other examples of common tasks.
- You can work with some parts of the Netflix API without being authorized by the user, but nothing too interesting—just searching the Netflix catalog for movies/TV shows.
If Firefox is preventing you from installing an add-on because it says the add-on isn’t compatible with your version of Firefox, but you think it might be, you can disable Firefox’s compatibility check with these simple steps:
- Type “about:config” in the URL bar and hit enter.
- Click “I’ll be careful, I promise.”
- Right-click anywhere on the page and choose New→Boolean.
- If you’re running Firefox 3.5 or lower, type “extensions.checkCompatibility”
- If you’re running Firefox 3.6, type “extensions.checkCompatibility.3.6”
- If you’re running an alpha of Firefox 3.7, type “extensions.checkCompatibility.3.7a”
- Set the value to false.