Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

setting up website in php


Hi,

I want to create API in PHP for uploading videos to jwplayer from an app and view those videos in app. And we are using PHP API for the same andI'm using JWPlayer for first time. So please guide where and how to start this as I downloaded PHP kit. But only one page is there in that kit.


Thanks & Regards
Priyanka

23 Community Answers

George

JW Player Support Agent  
-1 rated :

In general we disallow developers from giving end users access to the JW Platform and its API for two reasons:
1) Your API key would have to be available to make a call, this poses a security issue
2) Our API limit as mentioned in our Terms of Service

“…To ensure fair access for all, usage of api.jwplatform.com is limited to 60 calls per minute. Calls that exceed this rate will result in a 429 Rate Limit Exceeded error and will not be executed…”
https://developer.jwplayer.com/jw-platform/reference/v1/
https://www.jwplayer.com/tos/

Instead we suggest you setup an intermediate server that will “enqueue” the requests to JW Platform to ensure you stay below the API call limit and protect your API key.

The PHP-Kit can be found here:
https://developer.jwplayer.com/jw-platform/

Priyanka

User  
0 rated :

Now that I have created an intermediate server. But I want to upload videos from another server to this one. can you please give me an example code to upload videos to jwplayer server. As I am using PHP api for the same. Please guide me.

George

JW Player Support Agent  
1 rated :

Hello Priyanka,

I can only offer our platform API documentation:
https://developer.jwplayer.com/jw-platform/

You’re mostly looking for this:
https://developer.jwplayer.com/jw-platform/reference/v1/methods/videos/create.html

But you’ll also want to read these sections:
https://developer.jwplayer.com/jw-platform/reference/v1/call_syntax.html
https://developer.jwplayer.com/jw-platform/reference/v1/authentication.html

Priyanka

User  
0 rated :

Hello George,

I would like to know that just like in below link
https://developer.jwplayer.com/jw-platform/docs/developer-guide/management-api/uploading-videos/

Clack call is given for accessing videos from another url(server), Which method is used in PHP for the same. As I'm newbea for using web services. Please guide me.

Thanks
Priyanka

Priyanka

User  
0 rated :

Today I tried to get response from video/create and also tried to get other responses by using json_encode function of PHP. But all request response is giving me "False" as output. Please tell me what's the issue. Why I'm not able to access the jwplayer dashboard.

Todd

JW Player Support Agent  
1 rated :

Hi Priyanka,

You have three ways to upload videos to us using the JW Platform API:

1) normal file transfer
2) S3 Turbo uploads (faster but different syntax than option 1)
3) fetch upload, where you provide a URL to the video on an existing server and then we go grab it. This is the fastest file transfer speed and the easiest in the code since you do not have to make a second call after /videos/create

I have PHP code examples for all three scenarios, so I will paste them below.

Hope this helps,
Todd

Todd

JW Player Support Agent  
1 rated :

PHP basic upload (not S3, not fetch):

<?php
require_once('botr/api.php');
$botr_api = new BotrAPI('my_key', 'my_secret');

$target_file = 'bunny.mp4';
$params = array();
$params['title'] = 'PHP API Test Upload';
$params['description'] = 'Video description here';

$response = json_encode($botr_api->call('/videos/create', $params));

$jsonDecode = json_decode(trim($response), TRUE);
print $uploadUrl = $jsonDecode["link"]["protocol"]."://".$jsonDecode["link"]["address"].$jsonDecode["link"]["path"]."?api_format=xml&key=".$jsonDecode["link"]["query"]["key"]."&token=".$jsonDecode["link"]["query"]["token"];

$ch = curl_init($uploadUrl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data'));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
	'file' => curl_file_create($target_file)
]);

$response = curl_exec($ch);
curl_close($ch);

print $response;  
?>

Todd

JW Player Support Agent  
1 rated :

PHP S3 upload:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once('botr/api.php');
$botr_api = new BotrAPI('my_key', 'my_secret');

$params = array();
$params['title'] = 'S3 API Upload Test';
$params['description'] = 'Use the JW Platform API to upload videos';
$params['upload_method'] = 's3';

$response = json_encode($botr_api->call('/videos/create', $params));
$jsonDecode = json_decode(trim($response), TRUE);

print $uploadUrl = $jsonDecode["link"]["protocol"]."://".$jsonDecode["link"]["address"].$jsonDecode["link"]["path"]."?AWSAccessKeyId=".$jsonDecode["link"]["query"]["AWSAccessKeyId"]."&Expires=".$jsonDecode["link"]["query"]["Expires"]."&Signature=".urlencode($jsonDecode["link"]["query"]["Signature"]);

$target_file = "bunny.mp4";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, ''.$uploadUrl.'');
curl_setopt($ch, CURLOPT_PUT, 1);

$fh_res = fopen($target_file, 'r');
curl_setopt($ch, CURLOPT_INFILE, $fh_res);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($target_file));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_response_res = curl_exec ($ch);
fclose($fh_res);

print $curl_response_res;
?>

Todd

JW Player Support Agent  
1 rated :

PHP Fetch upload:

<?php
require_once('botr/api.php');
$botr_api = new BotrAPI('my_key', 'my_secret');

$params = array();
$params['title'] = 'Fetch Upload Test';
$params['description'] = 'Use the JW Platform API to upload videos';
$params['download_url'] = 'Full URL to the video I want to upload';

$response = json_encode($botr_api->call('/videos/create', $params));

print $response;
?>

Priyanka

User  
0 rated :

Thank You for your prompt reply and for the code snippet given but when I use the above code for uploading videos from remote url. I'm getting the response as "False"

Dont know why . But I tried above codes for many times. Even I opened new jwplayer account and tried with new api keys. But still the response is given as "False".

Priyanka

User  
0 rated :

Thank You. AS above issue has been resolved. AS our server is blocking outgoing connections for jwplayer server. Can you provide me list of IP address of jwplayer. So that I can add them in our outgoing connection lists. So that "false" error will not display.


And above code snippet works perfectly. But after uploading the video. I would like to show that video or embed that video to our website. So how to get the embed url for the same. Can you help me to solve this issue?

Thanks Once again
Priyanka

Todd

JW Player Support Agent  
1 rated :

We use many CDN partners and load balances, so there is not a list of IP addresses. Your best options are to allow traffic from the following domains:

*.jwplatform.com
*.jwpsrv.com
*.jwpcdn.com
jwpltx.com
jwpsrv.a.ssl.fastly.net

The response from /videos/create will include the new media ID assigned for this content. You can then access this video using the JSON feed:

http://cdn.jwplayer.com/v2/media/[mediaID]

Please see our Delivery API documentation at https://developer.jwplayer.com/jw-platform/docs/delivery-api-reference/ for more details. And please note that the video will need some time for transcoding. You can expect the video to be ready in real-time, so if you upload a 10 minute video, it will be ready in 10 minutes.

Priyanka

User  
0 rated :

Hi Todd,

Thanks for your last reply. I am very happy with your service.

But Now I want one more help from you. Hope that you'll help me in this case also.

As our web service is ready for fetching the video from remote url and upload it to jwplayer dashboard. But now I want to create ans API for the same. So that my API will fetch the videos automatically from remote server and upload it to jwplayer dashboard and give back response of uploaded video to remote server.

Please send me code snippet for the same. As I dont know anything about REST API. And this task needs to be completed with REST API only. Thanks once again

Priyanka

Todd

JW Player Support Agent  
0 rated :

I am afraid that I do not fully understand what you are trying to do.

Here is the way I understand it:

1) Fetch the videos automatically from remote server
2) Upload it to jwplayer dashboard
3) Give back response of uploaded video to remote server

Is this correct?

If yes:

1) This would depend on how you talk to the remote server. I am not able to assist with a code example for this as it does not include the JW APIs
2) I have provided code examples for the three methods to accomplish this
3) I have demonstrated how our API returns the response with the status, new media ID, etc, so passing that object back to the remote server can be accomplished in a few different ways, but I am not able to assist as this does not include any JW APIs

I wish I could be more helpful, but there are a number of ways to do #1 and #3 and I am not an expert with those as I focus on the use of our JW APIs.

Priyanka

User  
0 rated :

As you have given codes for fetching videos from remote url. That is ok and is working fine.

But remote url i.e. in C# is going to upload video from their domain and will call my api to upload that video to jwplayer dashboard via JW API.

And after uploading video, i have to send back reponse of video url of jwplayer to that remote C# domain.

So I have to create API for the same to run this functionality automatically. In short I will explain the flow as below:-

C# webpage will upload video-->Video url will be generated--> C# webpage will give call to PHP API(i.e.My API to be developed)--> PHP API will fetch that request --> Get Video from Request--> UPload it to JW player dashboard using JW API---> Get response from JW API--> SEnd response in the form of Video_url(i.e http://cdn.jwplayer.com/v2/media/[mediaID]) to C# page.

So this was the flow of video working.

Can you help me to implement API for the same. As I have never created on API. So no knowledge About this concept. Thanks in advance it will be great help for me.

Todd

JW Player Support Agent  
0 rated :

I have never created an API either, and I have never used C#, so I have no expertise or experience to offer. My responsibility is to help customers with the JW Player API methods, and I believe I have done that here.

I am sorry that I cannot assist further. My suggestion would be to try Stack Overflow.

Priyanka

User  
0 rated :

Hi Todd

Hope you doing well.
Finally I'm able to create my API for JW player video upload. But can you give me a code snippet to fetch the video key from the response we get after video upload from remote url ie.#3 code snippet . I only want to fetch video_key for the uploaded video. So that I'll send that Video_key in url to remote server. Please help me to do this task.

Thanks & Regrads

Priyanka

User  
0 rated :

I tried to get video key using #1 code i.e
========================================================================
$jsonDecode = json_decode(trim($response), TRUE);
print $uploadUrl = $jsonDecode["link"]["protocol"]."://".$jsonDecode["link"]["address"].$jsonDecode["link"]["path"]."?AWSAccessKeyId=".$jsonDecode["link"]["query"]["AWSAccessKeyId"]."&Expires=".$jsonDecode["link"]["query"]["Expires"]."&Signature=".urlencode($jsonDecode["link"]["query"]["Signature"]);
==========================================================================

I applied above code pattern in #3 code and write it as $key = $jsonDecode["video"]["key"]. And got key for the uploaded video.

But now I want to fetch 'sourceformat' i.e. mp4, flv, mp3, or any other format.
Please guide me to fetch the uploaded video format like as above code where i got key for the uploaded video.

Thanks & Regards

Todd

JW Player Support Agent  
0 rated :

If you just pointed to the source video, can’t you find the file format from that URL without doing the API call to us?

Once you know the media ID for any video, you can fetch all the known metadata from the JSON media feed:

https://developer.jwplayer.com/jw-platform/docs/delivery-api-reference/#!/media/get_v2_media_media_id

You can also make a /videos/show call, but this counts against your rate limit, but the JSON feed does not:

https://developer.jwplayer.com/jw-platform/reference/v1/methods/videos/show.html

Priyanka

User  
0 rated :

Hi Todd,

Thanks for above given information.
Now My API works fine and after making video/create call. Video got created on jwplayer dashboard. And I got link for the video uploaded to jwplayer dashboard but when I hit that link directly to the browser as soon as i got it, The browser shows "FIle Not Found" error. AS till that time video is getting uploaded to jwplayer server.

Please tell me any code or idea that I'll get time for uploading the video to jwplayer or any function where after upload completion I'll display the url for the video uploaded.

Thanks & Regards

Todd

JW Player Support Agent  
0 rated :

Our servers will need a few minutes to transcode any new uploads and make them available in our caches around the world. It is a 1:1 correlations, so I would expect a five minute long video to take about five minutes before the status is Ready at the initial transcode. Please note that it will take additional time to transcode the higher qualities of the video.

Your best option that does not require any API calls against your rate limit is to use the JSON /media/ endpoints I referred you to earlier. You know that each individual quality source is available when it appears in that JSON response. My suggestion would be to use the HLS playback source, if possible, as that will be the optimal viewing experience.

Priyanka

User  
0 rated :

Hi Todd,

I would like to check in my code that if video status will be ready then only display the video url otherwise no response will be given.

Right now when I call video/create function video got created to server and also I got video url from JWPlayer. But till the video gets uploaded I'm not able to view that video, bowser shows "File Not Found" error.

So I want to code in such a way that on after upload status will be "Ready" then only my page will send the response as a video url. Please help me to solve this issue.

Thanks & Regards

Todd

JW Player Support Agent  
1 rated :

You have two options:

1) Make a videos/show call using the media ID of the video in question, but please note that this will count towards your API rate limit

2) Request the /v2/media feed for that media ID, which does not count towards the API rate limit, but you will need to parse the response and check if the “processing” image URL is in use or for the sources: [] block containing MP4s before considering the video to be “ready”

For either option, my suggestion would be to wait for the full duration of the video to check for the first time, as our transcoders will need time to process the first quality variant. So if your video is five minutes long, I would wait five minutes before making the first status check using either of these two method. Our engineers are working on callback functions, but I would not expect these to be available until the end of 2017 at the earliest.

Hope this helps,
Todd

This question has received the maximum number of answers.