Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

391
Views
How to extract items from a youtube video using youTube API 3 and PHP

Im trying to extract the title and description of a youTube video using a php file.

So far, i was able to create the url and paste into chrome browser and i got the expected results.

Now, i want to do the same thing using a PHP file called from ajax. But, i get nothing.

Heres what i've done so far:

html

<span class="icon iDocument" data-do='{"do":"getYoutube", "path":"xxx"}'</span>

ajax.js

$("[data-do]").click(function(event) {
    var params = $(this).data("do");
    var action = params['do'];

    switch (action) {
        case "getYoutube":
            script = "/admin/include/action/get_youtube.php";

            $.ajax({
                type: "POST",
                url: script,
                data: params
            }).done(function(data) {
                alert(data);
            }).fail(function() {
                alert("Error.");
            }).always(function(data) {

            })

            break;

        default:
            break;
    }
});

get_youtube.php

<?php
if ( isset($_POST['path']) && trim($_POST['path']) != '' ) {
    $get_path = trim($_POST['path']); // for use later

    // work OK if paste in a browser (vars are harcoded for testing purposes)
    $url ="https://www.googleapis.com/youtube/v3/videos/?key=keygoeshere&id=videoidgoeshere&part=snippet";

    $video = json_decode($url, true);

    $test = $video['kind']; // for testing purposes

    echo $test;

} else {
    echo 'Video path not found';
}
?>

Im supposed to get an alert box with some data, but i get an empty alert box?

What am i doing wrong?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

$url ="https://www.googleapis.com/youtube/v3/videos/?key=keygoeshere&id=videoidgoeshere&part=snippet";

$video = json_decode($url, true);

Should be

$url = @file_get_contents("https://www.googleapis.com/youtube/v3/videos/?key=keygoeshere&id=videoidgoeshere&part=snippet");

$video = json_decode($url, true);
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!