0

So far i have tried below:

...

public function upload()
  {
    $jwplatform_api = new Jwplayer\JwplatformAPI('my_key', 'my_secret');

    $target_file = 'upload/vids/course/bede6b9c266b876fc2f0dea7a86cf8bd.mp4';
    $params = array();
    $params['title'] = 'PHP API Test Upload';
    $params['description'] = 'Video description here';

    // Create video metadata
    $create_response = json_encode($jwplatform_api->call('/videos/create', $params));
    $decoded = json_decode(trim($create_response), TRUE);
    $upload_link = $decoded['link'];

    $upload_response = $jwplatform_api->upload($upload_link, $target_file);

    print_r($upload_response);
  }

...

But no luck, it says "Class 'Jwplayer\JwplatformAPI' not found". And yeah, i have put the files I got from https://github.com/jwplayer/jwplatform-php in the ROOT position inside a folder named "jwplatform-php".

farisfath25
  • 71
  • 1
  • 8
  • 3
    i think you have to autoload the files here - its probably better to use composer. Take a look at https://stackoverflow.com/questions/32339582/codeigniter-composer and https://stackoverflow.com/questions/52574192/codeigniter-composer-package-json-locations-shluld-be-in-application-or-root-f – Atural Nov 13 '19 at 11:56
  • 1
    @farisfath25 if copying the directory, make sure to require the `init.php` file as documented in the README. Otherwise use composer. – Kamil Sindi Nov 13 '19 at 13:38
  • thanks @sintakonte, however i can't use composer. – farisfath25 Nov 15 '19 at 08:01
  • @ksindi : hmm i think i have seen that before, ok then i will try and post you the result later. thanks! – farisfath25 Nov 15 '19 at 08:01

1 Answers1

2

Ok since you don't want to use composer - here is a guide

1. Download as Zip

enter image description here

2. Create a folder

In your folder application/third_party/ create a folder called jwplatformapi/

3. Unpack the init.php and the src folder

Unpack from your zip file the init.php and the src folder into your application/third_party/jwplatformapi/ folder

it should looke like

enter image description here

4. Create your library

Create a file called Jwplatform_library.php in your application/libraries/ folder

class Jwplatform_library
{
    private $key;
    private $secret;

    public function __construct($key = 'my_key', $secret = 'my_secret')
    {
        $this->key = $key;
        $this->secret = $secret;
    }

    public function get()
    {
        require_once(APPPATH.'third_party/jwplatformapi/init.php');
        return new Jwplayer\JwplatformAPI($this->key, $this->secret);
    }
}

5. use it in one of your controllers

public function upload()
{
    $this->load->library('Jwplatform_library', ['my_key', 'my_secret']);
    $obj = $this->jwplatform_library->get();
    var_dump($obj);
}
Atural
  • 5,389
  • 5
  • 18
  • 35
  • This looks promising! Thank you for the clear and detailed step-by-step explanation. However, unfortunatrly I am unable to test it out now or even in a near future, hence I am planning to come back some days later because of my other priority in my project and notify you. Thanks once again, sir! – farisfath25 Nov 21 '19 at 09:47
  • it's been a while and I haven't tested it yet because I am no longer working on the same company. therefore, I just ticked this as accepted answer just because, I trust the person. – farisfath25 Jul 30 '20 at 02:46