PHP 如何从 VIMEO API 中提取 JSON 数据并将其打印到 XML 文件中?
How can PHP pull the JSON data from VIMEO API and print it on XML file?
我正在调用下面的VimeoAPI到return特定视频下的所有视频。我试图实现的是只提取我想要的特定 JSON 数据。 “uri”和“name”是我唯一需要的数据。我怎样才能将这个东西打印到 XML 文件中? https://developer.vimeo.com/api/reference/folders#get_project_videos
顺便说一句,这是我的尝试:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<?PHP
header('Content-Type: text/html; charset=utf-8');
require ("vendor/autoload.php");
use Vimeo\Vimeo;
$client = new Vimeo("{client_id}", "{client_secret}", "{access_token}");
$user_id = '121265018';
$project_id = '2370434';
$response = $client-
>request("/users/$user_id/projects/$project_id/videos");
var_dump($response);
if ($response['status'] === 200) {
$videos = [];
foreach ($response['data'] as $data) {
$result = [
//'uri' => $data['uri'],
'name' => $data['name'],
//'pictures' => $data['pictures'],
];
$videos[] = $result;
}
echo json_encode($videos, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} else {
echo json_encode($response['body']['error']);
}
?>
我认为你应该更换行
$jsondata = file_get_contents($response);
和
$jsondata = $response['body'];
你只需要将这三个东西保存在一个单独的数组中,然后以你想要的格式打印。
更新
您的所有视频都有一组数据。 sow 你需要使用 foreach 来获取所有视频的 uri、名称和图片并保存在另一个数组中。
<body>
<?PHP
header('Content-Type: text/html; charset=utf-8');
require("vendor/autoload.php");
use Vimeo\Vimeo;
$client = new Vimeo("{client_id}", "{client_secret}", "{access_token}");
$user_id = '121265018';
$project_id = '2370434';
$response = $client->request("/users/$user_id/projects/$project_id/videos");
if ($response['status'] === 200) {
$videos = [];
foreach ($response['body']['data'] as $data) {
$result = [
'uri' => $data['uri'],
'name' => $data['name'],
'pictures' => $data['pictures'],
];
$videos[] = $result;
}
echo json_encode($videos, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} else {
echo json_encode($response['body']['error']);
}
?>
</body>
我正在调用下面的VimeoAPI到return特定视频下的所有视频。我试图实现的是只提取我想要的特定 JSON 数据。 “uri”和“name”是我唯一需要的数据。我怎样才能将这个东西打印到 XML 文件中? https://developer.vimeo.com/api/reference/folders#get_project_videos
顺便说一句,这是我的尝试:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<?PHP
header('Content-Type: text/html; charset=utf-8');
require ("vendor/autoload.php");
use Vimeo\Vimeo;
$client = new Vimeo("{client_id}", "{client_secret}", "{access_token}");
$user_id = '121265018';
$project_id = '2370434';
$response = $client-
>request("/users/$user_id/projects/$project_id/videos");
var_dump($response);
if ($response['status'] === 200) {
$videos = [];
foreach ($response['data'] as $data) {
$result = [
//'uri' => $data['uri'],
'name' => $data['name'],
//'pictures' => $data['pictures'],
];
$videos[] = $result;
}
echo json_encode($videos, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} else {
echo json_encode($response['body']['error']);
}
?>
我认为你应该更换行
$jsondata = file_get_contents($response);
和
$jsondata = $response['body'];
你只需要将这三个东西保存在一个单独的数组中,然后以你想要的格式打印。
更新
您的所有视频都有一组数据。 sow 你需要使用 foreach 来获取所有视频的 uri、名称和图片并保存在另一个数组中。
<body>
<?PHP
header('Content-Type: text/html; charset=utf-8');
require("vendor/autoload.php");
use Vimeo\Vimeo;
$client = new Vimeo("{client_id}", "{client_secret}", "{access_token}");
$user_id = '121265018';
$project_id = '2370434';
$response = $client->request("/users/$user_id/projects/$project_id/videos");
if ($response['status'] === 200) {
$videos = [];
foreach ($response['body']['data'] as $data) {
$result = [
'uri' => $data['uri'],
'name' => $data['name'],
'pictures' => $data['pictures'],
];
$videos[] = $result;
}
echo json_encode($videos, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} else {
echo json_encode($response['body']['error']);
}
?>
</body>