samedi 27 octobre 2018

Youtube Data API v3 in Cordova dosent work

i tired of trying and i've searched before that on stackoverflow & internet , but i didnt find the solution , my code below using to collect links of playlist items to inner into (a href..) tag , the code works on "browser" platform , and also works on Normal browsing mode & console.log everything fine.

thereby i trying to run it on android platform but is not working!.

my code

<!-- Google API -->
<script type="text/javascript"> 
 var allVideos = new Array(); 
 function onGoogleLoad() { 
  gapi.client.setApiKey('xxxxxxxx'); 
  gapi.client.load('youtube', 'v3', function() { 

   GatherVideos("", function() { 

    allVideos.sort(function(a, b) { 
     return Date.parse(b.snippet.publishedAt) - Date.parse(a.snippet.publishedAt); 
    }) 

    for (var i = 0; i < allVideos.length; i++) { 
        console.log(allVideos[i].snippet.title +  allVideos[i].id);
        result = allVideos[i].snippet.resourceId.videoId + ' <br>';

        h1 = allVideos[i].snippet.title;
        document.getElementById('links').innerHTML += '<a href= https://youtube.com/watch?v='+result+''+h1+'</a>';

    } 
   }); 
  }); 
 } 

 function GatherVideos(pageToken, finished) { 
  var request = gapi.client.youtube.playlistItems.list({ 
   part: 'snippet', 
   playlistId: 'PLillGF-RfqbbnEGy3ROiLWk7JMCuSyQtX', 
   maxResults: 50, 
   pageToken: pageToken 
  }); 

  request.execute(function(response) { 
   allVideos = allVideos.concat(response.items); 
   if (!response.nextPageToken) 
    finished(); 
   else 
    GatherVideos(response.nextPageToken, finished); 
  }); 
 }
</script> 
<script src="https://apis.google.com/js/client.js?onload=onGoogleLoad"></script> 




Aucun commentaire:

Enregistrer un commentaire