Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3638

Membership verification API

$
0
0

Here is my code to check if the Google account trying to connect is subscribed or not to a specific YouTube channel and I wanted to use the same logic for membership but I didn't find anything.

How can I adapt the following code to test whether someone is a member or not?

<?phpsession_start();require_once 'vendor/autoload.php';if (!isset($_SESSION['access_token'])) {    header('Location: login.html');    exit();}$client = new Google_Client();$client->setAccessToken($_SESSION['access_token']);$youtube = new Google_Service_YouTube($client);$oauth2 = new Google_Service_Oauth2($client);$userInfo = $oauth2->userinfo->get();$userEmail = $userInfo->email;try {    $subscriptionsResponse = $youtube->subscriptions->listSubscriptions('snippet', ['mine' => true]);    $isSubscribed = false;    foreach ($subscriptionsResponse->getItems() as $subscription) {        if ($subscription->getSnippet()->getResourceId()->getChannelId() == 'UCDGmZYT5QfvfEXgzaEAYNpg') {            $isSubscribed = true;            break;        }    }    if ($isSubscribed) {        $_SESSION['user_email'] = $userEmail;        header('Location: form.html');        exit();    } else {        echo 'Vous devez être abonnéà notre chaîne YouTube pour accéder au formulaire.';        exit();    }} catch (Exception $e) {    echo 'Erreur lors de la récupération des abonnements : ' . $e->getMessage();    exit();}?>

Viewing all articles
Browse latest Browse all 3638

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>