jwplatform-php icon indicating copy to clipboard operation
jwplatform-php copied to clipboard

Call method on JwplatformAPI object return false

Open mbougarne opened this issue 6 years ago • 2 comments

Hello,

I'm working on a project for one of my client with Laravel, and they're using your platform to host their tuts videos. Anyway, I can't upload video to your platform using your API, the call method retune false without any more details.

This is my code.


<?php

namespace App\Services;

use Jwplayer\JwplatformAPI;
use Illuminate\Support\Facades\Log;
use App\Models\Setting;

class VideosUploadingService
{
    /**
     * JW API credentials
     *
     * @var \App\Models\Setting $settings
     */
    protected Setting $settings;

    /**
     * JW plat form API
     *
     * @var \Jwplayer\JwplatformAPI $jw
     */
    protected JwplatformAPI $jw;

    /**
     * JW Player API KEY
     *
     * @var string $api_key
     */
    protected string $api_key;

    /**
     * JW Player API SECRET
     *
     * @var string $api_secret
     */
    protected string $api_secret;

    /**
     * JW Player base upload URL
     *
     * @var string $api_secret
     */
    protected string $base_url;

    public function __construct()
    {
        $this->settings = Setting::first();
        $this->api_key = $this->settings->jw_player_api_key;
        $this->api_secret = $this->settings->jw_player_api_secret;
        $this->base_url = $this->settings->jw_player_base_url ?? '/videos/create';
    }

    /**
     * Upload video
     *
     * @param \Illuminate\Http\Request $request
     * @return string $response uploaded video link
     */
    public function upload($request)
    {
        $this->jw = new JwplatformAPI($this->api_key, $this->api_secret);

        $params = [
            'title' => $request->title,
            'description' => $request->description ?? $request->title
        ];

        $create = json_encode($this->jw->call($this->base_url, $params));
        $create_response = json_decode(trim($create), true);

        $response = $this->jw->upload($request->video_file, $create_response['link']);

        Log::alert('video create response => ' . $create);
        Log::alert('video uploaded response => ' . $response);

        return $response;
    }
}

mbougarne avatar Jun 03 '20 21:06 mbougarne

If anyone is interest, this error came because the API valid SSL certificate, download a certificate from https://curl.haxx.se/docs/caextract.html and configure in your php.ini like this

[curl] ; A default value for the CURLOPT_CAINFO option. This is required to be an ; absolute path. curl.cainfo = "C:\tools\cert\cacert.pem"

Hope this help

miguelromero-24 avatar Jun 28 '20 04:06 miguelromero-24

@salamand3r Thank you, but we created our implementation from scratch!

mbougarne avatar Jun 28 '20 13:06 mbougarne