Using PHP google client to get YouTube playlist (server-side oauth) -


i using php google_client youtube playlist data on web (a server-side oauth ,without user check ) error: redirect_uri_mismatch , message

the redirect uri in request, http://localhost/youtube/oauth2callback.php, not match ones authorized oauth client. visit https://console.developers.google.com/apis/credentialsoauthclient/112609190871896620853?project=756606231401 update authorized redirect uris.

here http://localhost/youtube/index.php code

<?php require_once 'vendor/autoload.php';  session_start();  $client = new google_client(); $client->addscope('https://www.googleapis.com/auth/youtube'); $client->setauthconfigfile('youtube-762b39a4f0b5.json');  if (isset($_session['access_token']) && $_session['access_token']) {   $client->setaccesstoken($_session['access_token']);   $youtube = new google_service_youtube($client);   $playlists = $youtube->playlists->listplaylists("snippet,status", array(       'channelid' => 'ucbbogoyxqdr-lrqrx7hdd6g'   ));   echo json_encode($playlists->tosimpleobject()); } else {    $redirect_uri = 'http://' . $_server['http_host'] . '/youtube/oauth2callback.php';   var_dump($redirect_uri);   header('location: ' . filter_var($redirect_uri, filter_sanitize_url)); } 

here http://localhost/youtube/oauth2callback.php

<?php require_once __dir__.'/vendor/autoload.php';  session_start();  $client = new google_client(); $client->setauthconfigfile('client_secret.json'); $client->setredirecturi('http://' . $_server['http_host'] .'/youtube/oauth2callback.php'); $client->addscope('https://www.googleapis.com/auth/youtube');  if (! isset($_get['code'])) {   $auth_url = $client->createauthurl();   header('location: ' . filter_var($auth_url, filter_sanitize_url)); } else {   $client->authenticate($_get['code']);   $_session['access_token'] = $client->getaccesstoken();    $redirect_uri = 'http://' . $_server['http_host'] .  '/youtube/index.php';   header('location: ' . filter_var($redirect_uri, filter_sanitize_url)); } 

any idea?

looking @ screenshots, have created service account. service accounts use two-legged oauth, , therefore not have user-consent-and-redirect dance.

a service account not have permissions videos in personal gmail account. maybe that's ok, maybe isn't. depends on use case don't describe in question. if need application act same permissions gmail account, you'll need use different technique. (described how authorise app (web or installed) without user intervention? (canonical ?) , https://www.youtube.com/watch?v=hfwe1gpcnzc)


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -