Created
April 14, 2018 08:04
-
-
Save ArvinH/42ad574cd8caf6ccd55afa7e2ad9c43a to your computer and use it in GitHub Desktop.
Sample code for handling vimeo api in python server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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