How to upload video to youtube using stupeflix API
The Stupeflix is an webservice to create and process videos using photos, audio and Upload videose. To upload videos to youtube using Stupeflix API we need to do the following steps
-
Signup for an developer account using link https://developer.stupeflix.com
-
Generate an API key
Click 'Generate an API' link in the home page it will redirect to an another page with a form. Click Create button,
after filling Usage Description and Application/Website url text boxes in the form. We will get an API key it is the pair of Access
key and Secret key. The generated secret key is passed as authorization key when we send the request to Stupeflix API. -
Download Requests library supported by stuplefix using the link http://requests.ryanmccue.info/
-
Find the developer key and access token
Youtube Developer Key (Client ID) and Youtube Oauth2 Access Token is the input parameters of the
video.upload.youtube methode. For getting these keys click Manage your YouTube Access Tokens link from this url
https://developer.stupeflix.com/tasks/video.upload.youtube/.It will redirect to an page, click create new access token button which redirects to an gmail accounts. Select an account, because stupeflix upload videose using the account selcted. After confirming the mail id we can get Youtube Developer Key and Youtube Oauth2 Access Token
-
Write a function to upload video in to youtube
Stupeflix provide codes for create and process videos using several methods such as video.upload.youtube, video.create,
video.strip, video.reverse etc in link https://developer.stupeflix.com/documentation/ in different
langauage like php, python, java etc. Please see the code for upload video to youtube in php.require_once "path/to/Requests/library/Requests.php"; Requests::register_autoloader(); $headers = array("Authorization" => "Secret PUT_YOUR_SECRET_KEY_HERE"); $data = array( "tasks" => array( "task_name" => "video.upload.youtube", "developer_key" => "Your Youtube Developer Key (Client ID)", "access_token" => "Your Youtube Oauth2 Access Token", "url" => "https://s3.amazonaws.com/stupeflix-assets/apiusecase/video.mp4", "title" => "Test Video", "description" => "Test youtube video using Stupeflix API", "category_id" => "22", "tags" => array("stupeflix"), "privacy_status" => "public" ) ); $response = Requests::post("https://dragon.stupeflix.com/v2/create", $headers, json_encode($data)); $taskCreation = json_decode($response->body); $response = Requests::get("https://dragon.stupeflix.com/v2/status?tasks=" . $taskCreation[0]->key, $headers); $taskStatusAndResult = json_decode($response->body); /* $taskStatusAndResult[0]->status can be either "queued", "executing", "success" or "error" */
Work flow of the code is
- Specify the Authorization header that contains the secret key in an API keys .
- Specify the tasks' parameters. Task parameter is the task_name(Stupeflix methode name for example video.upload.youtube for uploading video
and video.create for generating video)
, developer_key(Youtube Developer Key, we get it from the 4'th step), access_token(Youtube Oauth2 Access Token we get it from the 4'th step),
url(url of the uploaded video) etc - Send a POST request to the /create method, with the parameters serialized in json into the body of the request.
- Decode the response, deserialize the json body,its containing the task's status such as a "queued", "executing", "success" or "error" and
its key. - Send task key as query string parameter for sending a GET request to the /status method.
- Decode the response and deserialize the json body containing the status and result if the status is successful.
The status of the response can be either "queued", "executing", "success" or "error".
When the status is "success" we can retrieve the link of the youtube uploaded video using code
$taskStatusAndResult[0]['result']['export'].