Created
April 25, 2018 04:20
-
-
Save alanma/9f76d0e34ff3f6d411a15886a770574a to your computer and use it in GitHub Desktop.
Upload to YouTube
This file contains hidden or 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
#!/bin/sh | |
# Upload the given video file to your YouTube channel. | |
# https://stackoverflow.com/questions/19449061/upload-videos-to-my-youtube-channel-without-user-authentication-using-youtubeapi | |
# https://stackoverflow.com/questions/13274173/upload-video-on-youtube-using-curl-and-api-v3 | |
cid_base_url="apps.googleusercontent.com" | |
client_id="<YOUR_CLIENT_ID>.$cid_base_url" | |
client_secret="<YOUR_CLIENT_SECRET>" | |
refresh_token="<YOUR_REFRESH_TOKEN>" | |
token_url="https://accounts.google.com/o/oauth2/token" | |
api_base_url="https://www.googleapis.com/upload/youtube/v3" | |
api_url="$api_base_url/videos?uploadType=resumable&part=snippet" | |
access_token=$(curl -H "Content-Type: application/x-www-form-urlencoded" -d refresh_token="$refresh_token" -d client_id="$client_id" -d client_secret="$client_secret" -d grant_type="refresh_token" $token_url|awk -F '"' '/access/{print $4}') | |
auth_header="Authorization: Bearer $access_token" | |
upload_url=$(curl -I -X POST -H "$auth_header" "$api_url"|awk -F ' |\r' '/loc/{print $2}'); curl -v -X POST --data-binary "@$1" -H "$auth_header" "$upload_url" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment