I am trying to get youtube channel stats using Youtube APIs, it is giving me error like below. I have also mentioed the API script that I get from Youtube APIs Explore (API Playground method)
{"error": {"code": 403,"message": "Forbidden","errors": [ {"message": "Forbidden","domain": "global","reason": "forbidden" } ] }}UPDATE
Request that is being made,(get from Youtube APIs Explorer)
$client = new Google_Client();$client->setApplicationName('API code samples');$client->setScopes(['https://www.googleapis.com/auth/youtube.readonly',]);$client->setAuthConfig('YOUR_CLIENT_SECRET_FILE.json');$client->setAccessType('offline');$authUrl = $client->createAuthUrl();printf("Open this link in your browser:\n%s\n", $authUrl);print('Enter verification code: ');$authCode = trim(fgets(STDIN));$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);$client->setAccessToken($accessToken);$service = new Google_Service_YouTubeAnalytics($client);$queryParams = ['dimensions' => 'ageGroup,gender','endDate' => '2022-01-01','ids' => 'channel==UCTVujeJyggsTZnlnsdaP0dQ','metrics' => 'viewerPercentage','sort' => 'gender,ageGroup','startDate' => '2017-01-01'];$response = $service->reports->query($queryParams);print_r($response);
