I am calling the following Vimeo API to return all the videos under the specific videos. What I was trying to achieve is to only pull the particular JSON data that I desire to. “uri” and “name” is the only data that i need. And how can I print this thing to a XML file? https://developer.vimeo.com/api/reference/folders#get_project_videos
BTW this is my attempt:
<!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 VimeoVimeo; $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']); } ?>
Advertisement
Answer
You just need to save the three things in a separate array and then print at the format that you want.
UPDATE
you have an array of data with all your videos. sow you need to use a foreach to get uri, name and pictures of all videos and save in another array.
<body> <?PHP header('Content-Type: text/html; charset=utf-8'); require("vendor/autoload.php"); use VimeoVimeo; $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>