【问题标题】:How can I retrieve the URL of a video I have just uploaded?如何检索我刚刚上传的视频的 URL?
【发布时间】:2019-10-03 13:20:00
【问题描述】:

我有一个 Python 脚本,它通过 api 将视频文件推送到我们的 Vimeo 页面,效果很好。我只是无法检索我们刚刚上传的视频的链接。我在示例文档中找到了一个 sn-p,但它似乎不起作用。

import vimeo
import sys

client = vimeo.VimeoClient(
  token="xxxxx",
  key="xxxxx",
  secret="xxxxx"
)

# Make the request to the server for the "/me" endpoint.
about_me = client.get("/me")

# Make sure we got back a successful response.
assert about_me.status_code == 200

# Load the body"s JSON data. WORKS UP TO THIS LINE ENABLE BELOW
print (about_me.json())
#sys.exit(0)

# Path to upload file
path_to_file = r"C:\Users\mydocs\Documents\SS19xGEN.mp4"

print('Uploading: %s' % path_to_file)

# Push file with credentials
client.upload(path_to_file, data={'name': 'TEST', 'description': 'test'})

# Return the uri
print("The uri for the video is %s" % (client))

video_data = client.get(client + 'fields=link').json()
print(('"%s" has been uploaded to %s' % (path_to_file, video_data['link'])))

脚本运行良好,直到最后两行,这是我尝试检索我刚刚在脚本中上传的视频的 URL,但这给了我错误 =“发生异常:TypeError + 不支持的操作数类型:'VimeoClient' 和 'str'"

我已经翻阅了文档,但找不到任何如何执行此操作的示例,对于初学者的问题表示歉意!

【问题讨论】:

    标签: python api vimeo vimeo-api


    【解决方案1】:

    根据docsupload方法应该返回uri:

    # Push file with credentials
    video_uri = client.upload(path_to_file, data={'name': 'TEST', 'description': 'test'})
    
    # Return the uri
    print("The uri for the video is %s" % (video_uri))
    

    【讨论】:

    【解决方案2】:

    其他方式是使用参数sortper_page=1接收视频列表

    video_data = client.get('https://api.vimeo.com/me/videos?sort=date&per_page=1').json()    
    

    在url末尾添加你需要的fields

    【讨论】:

    • 知道如何获取嵌入代码吗? IE "player.vimeo.com/video/xxxx" 而不是 - vimeo.com/xxxxx
    • 1) “序列化”来自 uri 的数字(我们称它为 videoID(请看这里 stackoverflow.com/questions/56118069/…,阻止 # isolating digits)2)将它与目标 url 的一部分连接起来:@987654328 @
    猜你喜欢
    • 2014-11-26
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    相关资源
    最近更新 更多