Skip to content

Instantly share code, notes, and snippets.

@ArvinH
Created April 14, 2018 08:04
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 ArvinH/42ad574cd8caf6ccd55afa7e2ad9c43a to your computer and use it in GitHub Desktop.
Save ArvinH/42ad574cd8caf6ccd55afa7e2ad9c43a to your computer and use it in GitHub Desktop.
Sample code for handling vimeo api in python server
from flask import Flask, Blueprint, request, current_app, jsonify
import requests
import json
video_blueprint = Blueprint(
'video',
__name__
)
@video_blueprint.route('/vimeo', methods=['POST'])
"""
create video and get video upload link
"""
def post_vimeo():
data = request.get_json()
client_accessToken=current_app.config['VIMEO_ACCESS_TOKEN']
headers = {
'Authorization': 'bearer {}'.format(client_accessToken),
'Content-Type': 'application/json'
}
resp = requests.post('https://api.vimeo.com/me/videos', json=data, headers=headers)
responseJson = resp.json()
response = jsonify({ 'status': 'success', 'uploadLink': responseJson['upload']['upload_link'], 'videoUri': responseJson['uri']})
return response
@video_blueprint.route('/vimeo/videos/<videoId>', methods=['GET'])
"""
get video link to embed in video tag
"""
def get_vimeo(videoId):
client_accessToken=current_app.config['VIMEO_ACCESS_TOKEN']
headers = {
'Authorization': 'bearer {}'.format(client_accessToken),
'Content-Type': 'application/json'
}
resp = requests.get('https://api.vimeo.com/videos/{}'.format(videoId), headers=headers)
responseJson = resp.json()
print(responseJson)
response = jsonify({ 'status': 'success', 'data': responseJson['download'][0]['link']})
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment