youtube api - How to Get Channel id or url after Google Oauth PHP -


i trying code application system youtube login. have issue after required authorisation oauth 2.0 want choosen youtube channel id in string not can please me.

    $client = new google_client();     $client->setclientid($client_id);     $client->setclientsecret($client_secret);     $client->setredirecturi($redirect_uri);     $client->setapplicationname("bytnetwork");     $client->setscopes(array('https://www.googleapis.com/auth/userinfo.profile',      'https://www.googleapis.com/auth/yt-analytics.readonly'         ));  if (isset($_session['access_token']) && $_session['access_token']) {   $client->setaccesstoken($_session['access_token']); } else {   $authurl = $client->createauthurl(); } 

so after want string like

$channelid = "xxxxx"; use in code below

$data = file_get_contents('http://gdata.youtube.com/feeds/api/users/$channelid?alt=json'); $data = json_decode($data, true); $stats_data = $data['entry']['yt$statistics']; $medya = $data['entry']['media$thumbnail']; //yt$username kısmından kanal adı parse edilir  /**********************************************************/ echo "<img src='$medya[url]'></img><br>"; echo "subscribers: $stats_data[subscribercount]<br>"; echo "views: $stats_data[totaluploadviews]<br>"; 

using oauth 2, can refresh_token , access_token requested scope(s). if want youtube channel-id, authorized user, using access_token, send request:

https://www.googleapis.com/youtube/v3/channels?part=id&mine=true&access_token=hereyouraccesstoken 

in request above need replace string "hereyouraccesstoken". respone json string. , channel-id in field named: items['id'] (or items.id).

note, access_token expires after 1 hour. if so, use refresh_token obtain new one, refresh_token valid until revoked owner.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -