Skip to content

Instantly share code, notes, and snippets.

@amfelds
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amfelds/bf1510965946f4f0f4ad to your computer and use it in GitHub Desktop.
Save amfelds/bf1510965946f4f0f4ad to your computer and use it in GitHub Desktop.
Dropbox API sample code for Video Hack Day 2015
######
# This app generates streaming and sharing links for any video files that the user puts into the app's folder.
######
######
# Authenticate User
######
from pprint import pprint
from time import sleep
# Include the Dropbox SDK
import dropbox
# Get your app key and secret from the Dropbox developer website
# (This code works best if you create an app with App folder permission, and then put a video file in the folder)
app_key = ''
app_secret = ''
flow = dropbox.client.DropboxOAuth2FlowNoRedirect(app_key, app_secret)
# Have the user sign in and authorize this token
authorize_url = flow.start()
print '1. Go to: ' + authorize_url
print '2. Click "Allow" (you might have to log in first)'
print '3. Copy the authorization code.'
code = raw_input("Enter the authorization code here: ").strip()
# This will fail if the user enters an invalid authorization code
access_token, user_id = flow.finish(code)
pprint(access_token)
#####
# Look at the files in the App folder, get links for videos
#####
client = dropbox.client.DropboxClient(access_token)
folder_metadata = client.metadata('/')
pprint(folder_metadata)
for entry in folder_metadata['contents']:
# Feel free to add more file path extensions to find more videos
if (entry['path'].endswith('.mp4') or entry['path'].endswith('.mov')):
streaming_link = client.media(entry['path'])
sharable_link = client.share(entry['path'],True)
# Paste these links into video-page.html
pprint(sharable_link['url'])
pprint(streaming_link['url'])
<!DOCTYPE html>
<html>
<head><title>DBX at VHD</title></head>
<body>
<h2>Dropbox Video Demo</h2>
<div>
<!-- Add your sharable link to the href -->
<a href="" target="_blank">Comment and download</a>
</div>
<video width="640" height="480" controls>
<!-- Add your streaming link to the src -->
<source src="" type="video/mp4">
Your browser does not support the video tag.
</video>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment