beyond
beyond

Reputation: 81

How to call a Vimeo API in php?

I am trying to run this API(https://developer.vimeo.com/api/reference/videos#get_video). My goal is to call the API and print out the result, because after I run the the code, nothing is printed from the API call. Appreciate if anyone can help me. Thanks :

FYI, these are my code:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
      <?php
      require ("vendor/autoload.php");
  use Vimeo\Vimeo;
  $client = new Vimeo("{client_id}", "{client_secret}", "{access_token}");

   $video_id ="447518879";
   $response = $client->request("/videos/$video_id");
   //var_dump($response['body']);

   if($response['status'] === 200){
     echo json_encode($response['body']['message']);
   }
  else {
      echo json_encode($response['body']['error']);
  }

       ?>
  </body>
</html>

Upvotes: 1

Views: 1535

Answers (1)

Andr&#233; Walker
Andr&#233; Walker

Reputation: 633

according to Vimeo API for PHP. the response it's an array with have body, header and status. Vimeo API PHP

Response description

to access the body. put this in your code:

var_dump($response['body']);

if you wanna print as a JSON in your page:

echo json_encode($response['body']);

I tested this script bellow in here. and it's working fine:

require 'vendor/autoload.php';
$client = new Vimeo("{client_id}", "{client_secret}", "{access_token}");
$video_id = "451686900";
$response = $client->request("/videos/$video_id");

print_r($response);

Upvotes: 1

Related Questions