如何在PHP中调用Vimeo API? [英] How to call a Vimeo API in php?
问题描述
我正在尝试运行此API( https://developer.vimeo.com/api/reference/videos#get_video ).我的目标是调用API并打印出结果,因为在运行代码后,API调用不会打印任何内容.感谢有人可以帮助我.谢谢:
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>
推荐答案
(根据适用于PHP的Vimeo API).响应是一个具有正文,标题和状态的数组. Vimeo API PHP
according to Vimeo API for PHP. the response it's an array with have body, header and status. Vimeo API PHP
访问身体.将其放在您的代码中:
to access the body. put this in your code:
var_dump($response['body']);
如果要在页面中打印为JSON:
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);
这篇关于如何在PHP中调用Vimeo API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!