Php İle Youtube kullanımı ( resmi veya illegal api olabilir ) |
15 Mesajlar | 2.946 Okunma |
require_once __DIR__.'/vendor/autoload.php';
session_start();
$client = new Google_Client();
$client->setAuthConfig('oauthkimligi-buraya-sizin-dosya-adınız-gelecek.json');
$client->addScope(Google_Service_YouTube::YOUTUBE_READONLY);
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$service = new Google_Service_YouTube($client);
$response=liste($service, 'subscriberSnippet', array('myRecentSubscribers' => true,'maxResults' =>50));
//echo "";
//print_r($response); //Bütün aboneleri dizi şeklinde görüntüleme
//print_r( $response[0]); //İlk abone bilgilerini görüntüleme
echo '
Kanal Adı Fotoğraf Kanal ID\'si ';
foreach($response['items'] as $say) {
echo ''.$say['subscriberSnippet']['title'].' '.$say['subscriberSnippet']['channelId'].' ';
}
echo '
';
} else {
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/proje/admin/sistem/oauth2callback.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
// Call channels.list to retrieve information
function liste($service, $part, $params) {
$params = array_filter($params);
$response = $service->subscriptions->listSubscriptions(
$part,$params);
return $response;
}
?>
require_once __DIR__.'/vendor/autoload.php';
session_start();
$client = new Google_Client();
$client->setAuthConfigFile('oauthkimligi-buraya-sizin-dosya-adınız-gelecek.json');
$client->addScope(Google_Service_YouTube::YOUTUBE_READONLY);
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/proje/admin/sistem/oauth2callback.php');
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'] . '/proje/admin/sistem/youtube.php/';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}