YouTube API: Abort Resumable Upload - youtube-api

YouTube API Specification (https://developers.google.com/youtube/2.0/developers_guide_protocol_resumable_uploads) provides info about how checking the status and resume an incompleted upload.
But what about aborting a resumable upload? How long an incompleted upload can be resumed?

YouTube API does not provide this information directly.
It just says that
session URI has a finite lifetime and eventually expires
https://developers.google.com/youtube/v3/guides/using_resumable_upload_protocol
Google Drive talks about a week
A resumable session URI expires after one week.
https://developers.google.com/youtube/v3/guides/using_resumable_upload_protocol
https://developers.google.com/drive/api/v3/manage-uploads
Since the API is similar / same, it will be probably same

Related

Confusion about using YouTube Data API from the server or the client

I am building a website which uses the YouTube Data API. I am new to using such APIs.
My need:-
I need to receive videos and show its thumbnails.
My problem:-
If I use JavaScript to receive videos (I mean, from the client side), then my API KEY will be exposed.
My solution:-
I will use my server for such requests (to the YouTube Data API) and my client side will receive the YouTube Data API response through AJAX to my server.
So, my solution worth the problem?

Streaming Video from Google Drive Fails After Access Token Expires

My app streams video from Google Drive. When it requests the URL, it retrieves an access token, but that expires after an hour causing the buffer to empty and the video to freeze.
I'm familiar with the hour limit on access tokens but unsure of how to use the refresh token to request a new access token while a video is still streaming since that would change the URL AVPlayer is using. Any tips?

Why I cannot resume uploading a video to youtube with a refreshed access token?

I'm attempting to use the resumable API to upload a video to YouTube with a refreshed access token. but I'm getting a 401 back when I've finished uploading the resumed part of the data. I get the following message back alongside the 401:
authError Invalid Credentials
But I can upload a new video with that refresh access token.
This is a bug on the server-side: https://stackoverflow.com/a/14320908/1970843, https://code.google.com/p/google-api-python-client/issues/detail?id=231, https://code.google.com/p/gdata-issues/issues/detail?id=5124

Can I do a resumable upload with a Google Cloud Storage signed URL?

Using Google Cloud Storage, I'd like to pass a client the necessary information to do a resumable upload. Is this possible?
Yes, this is possible.
With a server that has authenticated to the Cloud Storage service and a client it wishes to grant access to, the typical signed URL upload workflow looks like this:
Client requests a signature so it can do a PUT
Your server creates and returns a signed URL using the method described here
Client does a PUT with the returned URL
The resumable workflow looks like this:
Client requests a signature so it can do a PUT
Your server does creates and returns a signed URL using the method described here
Your server makes a POST request to initiate the resumable upload as described here
Your server returns both the URL and the Upload ID to the client
Client does one or more PUTs using the provided URL and Upload ID
I just found this note on the docs here:
Note: If your users are only uploading resources (writing) to an access-controlled bucket, you can use the resumable uploads functionality of Google Cloud Storage, and avoid signing URLs or requiring a Google account. In a resumable upload scenario, your (server-side) code authenticates and initiates an upload to Google Cloud Storage without actually uploading any data. The initiation request returns an upload ID, which can then be used in a client request to upload the data. The client request does not need to be signed because the upload ID, in effect, acts as an authentication token. If you choose this path, be sure to transmit the upload ID over HTTPS.
So basically you don't need a signed url. The upload ID would be enough. The procedure would be as follows:
Client requests an upload so it can do a PUT
Your server makes a POST request to initiate the resumable upload.
Your server returns the upload id to the client.
Client does a PUT to upload the file using the provided upload id.

youtube browser based uploader yt:authentication Unknown

I had used my php AP for uploading youtube videos for 2 days,
All worked just fine.
But yesterday and today, I get this error when trying to upload videos to my youtube account.
yt:authentication Unknown
I am using OAuth2, all clientid , key, secret are correct
Any help ?
Whenever running into OAuth 2 weirdness, the first step I'd recommend is invalidating your existing grant from https://accounts.google.com/IssuedAuthSubTokens, and then going through the OAuth 2 approval flow again from scratch.
I have been using the PHP client library for the Google API and was having this same problem. In the v3 documentation, I couldn't find anything relating to a browser-based YouTube upload so I've ended up using the v3 API for some things (video and playlist retrieval, authentication etc.) but I'm still using the v2 method for browser-based uploading. All of this was working fine then suddenly stopped working. Jeff's suggestion of revoking the token does indeed work but the problem would just come back later.
What I had to do was check if the user's token had expired. Note that the YouTube token currently seems to expire after 60 minutes. If the token has expired, you need to make sure the user goes through the authentication process again. A quick example:
// $client is your previously authenticated instance of Google_Client
if ($client->isAccessTokenExpired())
{
// Redirect to your page which outputs $client->createAuthUrl() for them to authenticate again
}
It's probably worthwhile noting that $client->getAccessToken() still evaluates to true in conditionals even with an expired token.

Resources