Processing abandoned The video could not be processed - Youtube API?

Viewed 1169

I am uploading mp4 videos through my website using youtube data v3 api and the http post request looks like:

access_token = request.session['access_token']
url = "https://www.googleapis.com/upload/youtube/v3/videos?part=snippet"

    payload = {
        'snippet':{
            "categoryId": "22",
            "description": "Description of uploaded video.",
            "title": "Test video upload."
        }
    }
    files = [
        ('media_body', request.FILES['media_body'])
    ]
    headers = {
        'Content-Type': 'video/mp4',
        'Authorization': 'Bearer '+access_token,
    }

    response = requests.request("POST", url, headers=headers, data=payload, files=files)

    print(response.text.encode('utf8'))

    context = {
        'r': response
    }
    return render_to_response('dashboard/manage_content/youtube.html', context)

And this is the response I get:

{ "kind": "youtube#video", "etag": "yS7DhsHOhsDM-vXZiGUmLXcKST0", "id": "dII224dYC2o", "snippet": { "publishedAt": "2020-07-03T12:11:43Z", "channelId": "UCmv2Sec30iBc13b7ntf93Ow", "title": "unknown", "description": "", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/dII224dYC2o/default.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/dII224dYC2o/mqdefault.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/dII224dYC2o/hqdefault.jpg", "width": 480, "height": 360 } }, "channelTitle": "Nikhil Dhoot", "categoryId": "20", "liveBroadcastContent": "none", "localized": { "title": "unknown", "description": "" } } }

But on the videos tab, I get the error: Processing abandoned The video could not be processed. The fact that the video responds a success message means that all the authentication process before it has been successful. However, if required I can edit and share that code too.

1 Answers

Uploading a video to YouTube is a two-step process:

  1. Invoke the Videos.insert API endpoint, posting to that a proper JSON text describing your video.

  2. Upon the API call, get the location where to actually upload the video content from the API endpoint response. Then do the actual content uploading operation.

Do scrutinize the source code Google made publicly available w.r.t uploading videos on YouTube. You'll learn all the concrete details of the algorithm I sketched above.

If you'd like to go deeper into how the call request.next_chunk() in function resumable_upload works, then go read the relevant part -- the method HttpRequest.next_chunk -- in file http.py of Google's API Client Library for Python.

Related