Hello,
I need your help guys;)
I want to display the data from YT in vd: the amount of views on a particular channel and the total number of videos
I have a direct link that displays information in JSON:
https://www.googleapis.com/youtube/v3/channels?part=statistics&id={CHANNEL_ID}&key={YOUR_API_KEY}
If I put it in web browser, I see the following information:
// 20170117085953
// https://www.googleapis.com/youtube/v3/channels?part=statistics&id={CHANNEL_ID}&key={MY_API_KEY}
{
"kind": "youtube#channelListResponse",
"etag": "\"gMxXHe-zin558lTnzKu8vjcmDI/2Qud556x4kgLe-969qH7-65gh7t\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"gMxXHe-zinKdE9TTEzKu8vjcmDI/q3O415qUconyEsljnEa554j5mM\"",
"id": "{CHANNEL_ID}",
"statistics": {
"viewCount": "34315",
"commentCount": "0",
"subscriberCount": "76",
"hiddenSubscriberCount": false,
"videoCount": "74"
}
}
]
}
I want to import from the above data to VD following information:
viewCount":
videoCount":
I know that the connection to the data is encrypted (via https), so I created a php script and put it on my server:
<?php
$url = fopen( ‚https://www.googleapis.com/youtube/v3/channels?part=statistics&id={CHANNEL_ID}&key={MY_API_KEY}’, ‚r’ );
$wynik = ”;
while (!feof($url)) {
$wynik .= fread($url, 8192);
}
fclose( $url );
header(‚Content-Type: application/json’);
print_r($wynik);
?>
Then I created of virtual device on the Home Center:
HC2 = Net.FHttp(„ADDRESS_OF_MY_HOSTING”,80);
dane ,status, errorCode = HC2:GET(„/PHPFILE.php”);
ajson=json.decode(dane)
view=ajson.items[1].statistics.viewCount
fibaro:call(195,’setProperty’,’ui.Label1.value’,tostring(view))
video=ajson.items[1].statistics.videoCount
fibaro:call(195,’setProperty’,’ui.Label2.value’,tostring(video))
The problem is that it does not collect any data from YouTube.
In main look I see:
line 2: unexpected symbol near '�'
If anyone has any idea where I made a mistake or how I can accomplish in a different way?