Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download recording files, easily? #82

Closed
BioSehnsucht opened this issue Jan 28, 2021 · 4 comments
Closed

Download recording files, easily? #82

BioSehnsucht opened this issue Jan 28, 2021 · 4 comments

Comments

@BioSehnsucht
Copy link

I can borrow the JWT functionality (slightly modified copy paste from src/Support/Entry.php) to get a new token and append it to the URL with parameter access_token in order to download the files with curl, but this is a bit ugly.

Is there a way to get the current active JWT token that laravel-zoom is itself using already, or better yet could we get added functionality for downloading files to make it a simple function call instead of doing all the curl ourselves? This is my first time using Laravel so there may be a really obvious solution that I just don't see (I don't even understand how the JWT calls work normally, since I didn't see where newRequest even gets called to get a JWT token to begin with ... )

Example code that works to show how I'm achieving this now (this is ugly test code just to figure out how to do it, after using some other ugly test code to find a download url for one of the recording files)

    public function handle()
    {
        $zoom = new \MacsiDigital\Zoom\Support\Entry;
        $account = new \MacsiDigital\Zoom\User($zoom);
        $apiKey = config('zoom.api_key');
        $apiSecret = config('zoom.api_secret');
        $tokenLife = config('zoom.token_life');
        $jwtToken = JWT::generateToken(['iss' => $apiKey, 'exp' => time() + $tokenLife], $apiSecret);
        $outputFile = 'OUTPUT_FILENAME';
        $downloadUrl = 'YOUR_DOWNLOAD_URL_HERE';
        $fp = fopen($outputFile,'w+');
        $ch = curl_init($downloadUrl);
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_POSTFIELDS, 'access_token=' . $jwtToken);
        // Need to follow 302 to the actual download
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_exec($ch);
        $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        fclose($fp);
        $this->line('Curl: ' . $statusCode);
    }
@colinhall17
Copy link
Member

Hi @BioSehnsucht

The Zoom package utilises the Laravel HTTP client under the hood, which in turn uses the Guzzle HTTP Client. As you are attaching the token to the URL you don't need to use the Zoom Entry Point, you can just use the Http Client direct.

So first you would need to build a JWT token

$jwtToken = \MacsiDigital\API\Support\Authentication\JWT::generateToken(['iss' => config('zoom.api_key'), 'exp' => time() + config('zoom.token_life')], config('zoom.api_secret'));

Then you can build the HTTP Client

$client = \MacsiDigital\Zoom\Support\Client::withToken($jwtToken);

Form there you can then use any of the Laravel HTTP methods which are listed in the link below

https://laravel.com/docs/8.x/http-client#introduction

@BioSehnsucht
Copy link
Author

it seems ::withToken(...) doesn't exist?

   BadMethodCallException

  Method MacsiDigital\Zoom\Support\Client::withToken does not exist.

Using the Http client directly with withHeaders works though.

@colinhall17
Copy link
Member

colinhall17 commented Feb 2, 2021

Apologies it should have been

\Illuminate\Support\Facades\Http

and not

\MacsiDigital\Zoom\Support\Client

You need to hook into Laravels HTTP Client

Here is the documentation for the withToken method, however if you are passing the token in the URL, I am not 100% that setting the token is necessary, so you would need to experiment for your use case.

https://laravel.com/docs/8.x/http-client#bearer-tokens

@BioSehnsucht
Copy link
Author

You're right about the withToken thing for downloads, downloads pass it as a URL parameter. I did end up using withToken for getting recordings since I still haven't gotten the with/to functionality to work as it's supposed to (#67).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants