Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team
Question
oldman 0
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:
Please login or register to see this link.
If I put it in web browser, I see the following information:
// 20170117085953
//
Please login or register to see this link.
{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?
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.