I have video files stored on my web server which I want to be able to upload to YouTube in an automated kind of way. These videos are created on my website, which then the user can just upload to their YouTube Channel.
I am trying to make HTTP request calls to automate this video upload process, according to the Resumable Video Upload process here: https://developers.google.com/youtube/2.0/developers_guide_protocol_resumable_uploads
Everything works fine (getting the user's access permission, sending the metadata of the video) until the final step, which is the upload of the video itself. When I make the PUT request, it returns a response code 417 and says Invalid Request. Like this:
The following error was encountered:
Invalid Request
Some aspect of the HTTP Request is invalid. Possible problems:
Missing or unknown request method
Missing URL
Missing HTTP Identifier (HTTP/1.0)
Request is too large
Content-Length missing for POST or PUT requests
Illegal character in hostname; underscores are not allowed
I took a look at all those suggested possible problems, but I cannot find a fault anywhere in my code.
And the error message is just to vague and not specific enough to tell me where the problem is.
I am performing every step of the video upload process using the PHP's standard Http Request class. (http://www.php.net/manual/en/class.httprequest.php)
Here is my code:
$videoFile = *Some Video File*;
$httpRequest = new httpRequest($_SESSION['youtube_data_api']['upload_url'], HttpRequest::METH_PUT);
$httpRequest->setContentType('video/mp4');
$httpRequest->setPutFile($videoFile);
$headersArr = array('Content-Length' => strlen($httpRequest->getRawRequestMessage()));
$httpRequest->setHeaders($headersArr);
$httpMessage = $httpRequest->send();
I dug around on the internet a lot regarding this question, and a lot of times what I found are people using the Zend framework's YouTube library to accomplish this instead, which is a lot easier. Unfortunately, with the size of my website right now, it is just not feasible to spend some much time trying to integrate framework into my website.
Any insight into this problem would help tremendously! Thanks!
Related
Let's imagine that I have a video url on my site: it's like this: http://example.com/videos/myvideo.mp4 . I want to use Automatic (“pull”) uploads method to upload this video to vimeo. Then I simply want to host it on my site. The problem is that the documentation that they provide is kinda confusing to me (and possibly all other developers getting started with their api). So, from your experience can you tell me how to upload this video to that vimeo and get back the video url that has been uploaded?
I created the vimeo app as they said and I have requested the upload access. It says:
Upload Access
Approved for the following accounts:
Your account
So basically everything is setup. I just need to know what http request should I send to the vimeo server in order to upload that mp4 file that is accessible on the web.
The HTTP request is detailed in the pull upload section of the documentation: https://developer.vimeo.com/api/upload/videos#automatic-pull-uploads
An HTTP POST request to https://api.vimeo.com/me/videos with two required, and one optional parameter sent through the request body.
The official PHP library: https://github.com/vimeo/vimeo.php will help you make the upload request, and documentation on making requests using this library is located here: https://github.com/vimeo/vimeo.php#make-requests
Once you have all the pieces together, the request looks kind of like this:
$response = $lib->request('/me/videos', ['type'=>'pull','link'=>$url], 'POST');
Im using the PHP example code given in Youtube API v3 : https://developers.google.com/youtube/v3/docs/captions/download , to download captions from 3rd party, publicly available YouTube videos in my webapp i.e. I have NOT uploaded the content on Youtube.
I am able to get access to the list of caption tracks, but unable to download the caption using the caption track ID from the received list.
The error that shows up upon attempting to DOWNLOAD is:
Error calling GET https://
www.googleapis.com/youtube/v3/captions/Lw0e5xDNU17GFafOl8DcyeOtwzWJTf9V?tfmt=srt&alt=media:
(404) Not Found
(I have tried removing tfmt (optional parameter), but still gives an error.)
But the error is different for attempting to DELETE captions:
Error calling DELETE https://
www.googleapis.com/youtube/v3/captions?id=Lw0e5xDNU17GFafOl8DcyeOtwzWJTf9V:
(403) Forbidden
Therefore it seems that captions.download is NOT forbidden for users other than owner (just like the captions.list is NOT forbidden) and therefore I would like to use this data for my webapp.
Any help is gratefully received.
Thanks,
Nikhil
I just tried the URL you mentioned in a browser and in the API explorer, and in both cases I received a 401 when I had no oAuth token and a 403 when I had an access token (since I'm not the owner), so the endpoints are acting as intended; according to the documentation, downloading captions requires oAuth consent from the owner of the video.
Perhaps, if you're getting 404s instead, there's a problem in the PHP library?
I have found another way to access any YouTube video's caption data.
The code is written in Ruby.
Read Youtube transcript (captions) from any public Youtube video
Works great, I just need to find a way to integrate this with my webapp.
What I'm trying to do is basically use PHP to upload videos without ever going to youtube itself. Several people need to use a form and be able to upload stuff with all the authentication done server-side. During the upload process, the fact that it's going on Youtube shouldn't even be apparent(not a secret, just want the authentication done without directing to other places).
Like a year or two ago I used this tutorial:
http://www.damnsemicolon.com/php/php-upload-video-youtube-zend-gdata
But it seems as though Google has changed the way they authenticate because it doesn't work anymore. The same thing that worked before now displays:
*"Fatal error: Uncaught exception 'Zend_Gdata_App_AuthException' with message 'Authentication with Google failed. Reason: BadAuthentication'"*
I also got an email from google, which told me they blocked the "suspicious" behavior from my server. I used the Google Unlock Captcha to authorize access, as well as marked the behavior as me. That didn't fix the problem, so either that doesn't do anything or there is something else causing the issue.
I've been trying to build it from the ground up using documentation but I'm not good at understanding those things. Is there an easy fix to the code I used in the first link? Or has google made it impossible to post stuff to your own channel in this manner?
[password and such are correct]
As jlmcdonald pointed out, the authentication API for Youtube has moved away from ClientLogin to oAuth2 exclusively. Check out https://developers.google.com/youtube/v3/guides/moving_to_oauth for more information.
I've been visiting this forum for years, but this is my first ever question. Any help would be appreciated!
I am writing a web service to pass groups from one application into Facebook and invite the authorised people into them and set a nice pretty cover photo that is generated and stored within the application.
The group creation works splendidly after a fair old bit of head scratching, however, when I try to set the cover image, I am getting a rather useful error message back as below.
OAuth "Facebook Platform" "unknown_error" "An unknown error has occurred."
It's a PHP application on Code Igniter. According to Facebook's delightfully accurate API documentation, this is a simple matter of a cUrl post to 'graph.facebook.com/$groupId' passing the same auth token I just used to create the group and perform the invites and a single JSON encoded parameter of 'cover_url' => $urlOfImage .
A simple task in theory, however, I have spent all day today and a significant chunk of yesterday trying to get this to work without much success.
I have tried posting the image as a Curl object as is necessary in other areas of the Facebook API, and it appears to be trying giving me an error that the image is generating a 404 error (it isn't, when I checked the access logs, it was never requested).
Please be someone out there who has had some success with this.
This has now been fixed by Facebook
I need to know a method to upload a video to a VIMEO PRO account using a form and PHP (to get auth). Currently I can send a video directly to Vimeo, using the panel, as was to be expected. But I have some clients that want to upload your videos directly from my their control panel (created by me), outside of vimeo, and I have only a unique PRO account, and I can't share the account data.
Seems that I can do it, based on the page API https://developer.vimeo.com/apis/advanced/upload#post (Uploading via POST).
My doubts are:
Can I really do that, without pass to my clients the Vimeo PRO account data?
It's a secure method (considering that clients respect the agreement with Vimeo)?
I need to upload DIRECTLY to Vimeo, without pass to my server, because I'll have two works: one to upload to server, other to upload from server to vimeo.
Off-topic: I believe I will not have problems with Vimeo, since they are customers of one company, and the account belongs to the company, and the videos will be her responsibility.
How should work
User access my panel, with your credentials;
User access the video upload page;
Probably the server will contact Vimeo to get an uploader auth;
User will select your vimeo file and submit form;
System will receive the vimeo ID and everyone will be happy forever.
Thanks!
Edit: This feature is now supported by Vimeo's (in beta) API3. You can request access at https://vimeo.com/help/contact
The below information is still accurate in regards to the Advanced API
This feature is not reliably supported by the advanced api.
The primary issue is that with client side uploads, there is no way to tell the upload server what to do once the upload is complete. Additionally, there is no client side technique to find out whether the upload has completed
You might be able to cheat and have the user upload through an iframe, and have the primary page perform a verify chunks call every couple of seconds. I have not tried this, at the moment it is just a theory. If you attempt this hack, Vimeo would love to know more via their contact page https://vimeo.com/help/contact
The feature you are discussing is on the roadmap for the next version of the API, and an early imperfect version was available at their API Hackday. It might be a better idea to hold off a bit and wait for the official feature.
NOTE: This observation does NOT apply to server side uploads. Because the whole upload process is handled via code on the server, it is extremely easy to tell when an upload is complete.
Answering in 2016: Assuming you have already retrieved an access token from Vimeo (OAuth2) this is a good piece of code to help you create an upload form:
https://github.com/websemantics/vimeo-upload
This gives you the code for the form with a place to drag-drop your video file and calls the upload API:
If you're using WordPress, there is a plugin available that allows you to do just that
http://vimeography.com/add-ons/vimeography-upload/
Source: I made it :)