Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Nov 2013
    Location
    UK
    Posts
    42
    Thanks
    6
    Thanked 1 Time in 1 Post

    Problems getting data with gdata and json from youtube

    Hi all...if anyone could help me shed some light on this interesting case, I would be profoundly grateful...
    I have some clips on youtube, and on my server I made a "console" page, with the views gathered by each clip.
    Recently, I uploaded a new video - 2 days ago - and when I add that video to my php it just....hangs.....
    If I'm changing the value to one of the already existing videos, everything is perfect.... Is there a "waiting time" until the data becomes available ?

    Thanks for your time and, hopefully, your answers.

    My php retrieving file looks like:
    Code:
     
    <?php
    $id = array ('henIovW3438','VlbsqV6Nlyk','vg5w-8BBPGU','e1O9UCB389w','8CqyQT2vbNw','wqRkWuxxU4k','B85Qik4s8iY','N4iYY5N3OrQ','7yM5Gh_tY7I','8zyCqBBR3Oo','q02Sk0auK9s','PVsFJtpkE_M','X9JT9RLHTWU','qhkAOkfe_AI','gL-6pdmvClU','fUq3Uwv7Byw','tgk7CUaNmWk','r5s_OC6-Ohs','6b1CCaL8Cuo');
    $i=0;
    echo "var numarnou = new Array();\n";
    foreach ($id as $value)
    {
    $i=$i+1;
    $JSON = file_get_contents("https://gdata.youtube.com/feeds/api/videos?q={$value}&alt=json");
    $JSON_Data = json_decode($JSON);
    $views = $JSON_Data->{'feed'}->{'entry'}[0]->{'yt$statistics'}->{'viewCount'};
        echo "numarnou[$i]=$views;\n";
    }
    ?>
    The problem is with the last value of the array, the 6b1CCaL8Cuo . If I replace that with any of the other values... everything is ok. Any suggestions ?
    Thanks again

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    When you attach to the url directly, does it provide the proper result? If so, if you attempt to read it through any method in PHP, does it work if you do just the one and not in the loop?

    I'm curious on this one: yt$statistics. Is that the literal name for it? I noticed its within single quotes; that won't be parsed in PHP if $statistics is actually a variable.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Nov 2013
    Location
    UK
    Posts
    42
    Thanks
    6
    Thanked 1 Time in 1 Post
    Hi Fou Lu

    Thanks for your reply

    No; I checked it individually, and... no response from the youtube server.
    And still the address is correct...you can try it by going to it,and it opens
    So...I'm out of ideas
    And, as I said, this works perfectly for other clips... so I don't think yt:statistic is a problem

  • #4
    New Coder
    Join Date
    Nov 2013
    Location
    UK
    Posts
    42
    Thanks
    6
    Thanked 1 Time in 1 Post
    No ideas ? Anyone ?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Which part is the code is it hanging on, the retrieval or the decode?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    New Coder
    Join Date
    Nov 2013
    Location
    UK
    Posts
    42
    Thanks
    6
    Thanked 1 Time in 1 Post
    HI
    I have a htm from where I call the code and retrieve the numarnou[I] variable;
    works perfectly, but, as I said before, if I add the last address to be processed, nothing is re4turned; absolutely nothing; - means the whole code gets ignored ! if instead the new value I add another existing value...voila, everything is there ! Strange ! Can it be from youtube server, maybe it needs a couple of years to assimilate a newly added video in their system ?
    thanks

  • #7
    New Coder
    Join Date
    Nov 2013
    Location
    UK
    Posts
    42
    Thanks
    6
    Thanked 1 Time in 1 Post
    Hi...again....
    Thanks for everything, but it solved itself ! Don't ask me how, but suddenly it's working ! It seems that youtube may have a period of accommodation after all !
    Admin, please, can you close this tread as "solved" ? Haven't got a clue how to do that ! Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •