简体   繁体   English

如何获取 Google Drive 视频的直接链接(Google Drive API v3)

[英]How do I get the direct link for a Google Drive video (Google Drive API v3)

I'd like to make a function which converts Google Drive videos into VLC streamable links (eg vlc://https://WEBSITE.com/FILE_ID.mkv .我想做一个 function 将 Google Drive 视频转换为 VLC 流式链接(例如vlc://https://WEBSITE.com/FILE_ID.mkv

I've tried methods which were shared on stack overflow, such as modifying the Google Drive link to: https://drive.google.com/uc?export=download&id=FILE_ID我尝试过在堆栈溢出时共享的方法,例如将 Google Drive 链接修改为: https://drive.google.com/uc?export=download&id=FILE_ID

All the methods I've tried seem to not work anymore.我尝试过的所有方法似乎都不起作用了。 Any ideas?有任何想法吗?

I've figured out the answer.我已经找到答案了。

Google Drives' API has a download feature, you just need to make a request to https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY Google Drives 的 API 具有下载功能,您只需向https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY

Now this doesn't generate a direct file path ending with .mp4 or .mkv but VLC and PotPlayer are able to recognize this link like this:现在这不会生成以.mp4.mkv结尾的直接文件路径,但 VLC 和 PotPlayer 能够像这样识别这个链接:

potplayer://https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY vlc://https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY potplayer://https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY vlc://https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY

Edit: this doesn't work in development, Google prevents bots from making requests like that.编辑:这在开发中不起作用,谷歌阻止机器人发出这样的请求。 To work around this you need to set a header in your request.要解决此问题,您需要在请求中设置 header。 eg例如

url = "https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY"
r = requests.get(url, headers={"Authorization":"Bearer " + accessToken})

You get the accessToken from the Google Drive API您从 Google Drive API 获得accessToken

Just make the file public and copy your ID.只需将文件公开并复制您的 ID。 You can find it here: /file/d/ YOUR ID /view?usp=sharing.您可以在此处找到它:/file/d/您的 ID /view?usp=sharing。 Copy your ID and paste it in this: drive.google.com/uc?export=view&id= YOUR ID复制您的 ID 并将其粘贴到:drive.google.com/uc?export=view&id= YOUR ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM