Reputation: 357
I'm trying to upload a video url to Vimeo in Google Script. I've set this up successfully in my Python/Django app with the following:
url = 'https://api.vimeo.com/me/videos'
headers = {'Authorization': 'bearer xxx',
'Content-Type': 'application/json',
'Accept': 'application/vnd.vimeo.*+json;version=3.4'}
data = {'upload': {'approach': 'pull',
'link': 'https://video.mp4'}}
requests.post(url, headers=headers, data=json.dumps(data))
I tried to create the equivalent to the best of my knowledge in Google Scripts as follows:
var url = 'https://api.vimeo.com/me/videos'
var headers = {
'Authorization': 'bearer xxx', 'Content-Type' : 'application/json', 'Accept' : 'application/vnd.vimeo.*+json;version=3.4'}
var data = {'upload' :{ 'approach' : 'pull','link' : 'https://video.mp4'}}
var options = {
headers:headers,
data:data,
}
var response = UrlFetchApp.fetch(url,options)
I get a successful response, but it seems that I'm getting a list of existing videos on my account and no video is uploaded. Could anyone provide any insight into how I could reconfigure my Google Script set up. Thank you!
Upvotes: 0
Views: 1125
Reputation: 2072
Your Python code shows a POST request, but the Apps Script UrlFetchApp.fetch()
request doesn't specify the method, so it is defaulting to a GET request.
To make it a POST, include method: 'post'
in the options.
In addition, the data being posted should be labeled payload
in the options:
var url = 'https://api.vimeo.com/me/videos'
var headers = {
'Authorization': 'bearer xxx', 'Content-Type' : 'application/json', 'Accept' :
'application/vnd.vimeo.*+json;version=3.4'}
var data = {'upload' :{ 'approach' : 'pull','link' : 'https://video.mp4'}}
var options = {
method: 'post', // Add this line
headers:headers,
payload: JSON.stringify(data), // Change this line.
}
var response = UrlFetchApp.fetch(url,options)
Upvotes: 3