Click here to Skip to main content
15,867,961 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
​While using the youtube API to get the subscriptions,liked videos,upload videos and comments, and update the channel details of the authenticated user in our angular project using youtube APIs,we are getting 403 Forbidden error. It states that request had insufficient authentication scopes.

We have tried applying scope and access token to the API but still we get this error. Could any one help us with this error and provide suggestions based on it. Here I have attached the screenshot of the error message and our code.

What I have tried:

TypeScript
Subscription.ts:

import { Component, Input, OnInit } from '@angular/core';
import { YoutubeService } from '../youtube.service';

@Component({
  selector: 'app-subscriptions',
  templateUrl: './subscriptions.component.html',
  styleUrls: ['./subscriptions.component.css']
})
export class SubscriptionsComponent implements OnInit {
  firstname:any;
  account:any;
  User: boolean=false;
  subscription:any;
  access_token:any;
  
  
  constructor(private service:YoutubeService) {
    this.firstname=localStorage.getItem('name');
    this.access_token=localStorage.getItem('access_token');
   }

  ngOnInit(): void {
    console.log(this.firstname);
    if(this.firstname != null)
    {
      this.User=true;
      console.log(this.User);
    this.service.GetSubscriptions().subscribe((res:any) => {
      console.log(this.firstname);
      this.subscription=res.items;
      console.log(this.subscription);
     });
  }
}

}


Service .ts :

   import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { GoogleLoginProvider } from 'angularx-social-login';

@Injectable({
  providedIn: 'root'
})
export class YoutubeService {
  
  private APIURL = "https://youtube.googleapis.com/youtube/v3/";
  private APIKEY ="AIzaSyB40HaKwd0VggftBq8R9sEwQx_NG5xOOWc";
  SocialAuthService: any;
  access_token=localStorage.getItem('token');
  reqHeader:any;
  constructor(private http:HttpClient) {
    const reqHeader = new HttpHeaders().set('Authorization', 'Bearer ' + this.access_token)
    .set('Scope', 'https://www.googleapis.com/auth/youtube.readonly')
   }
 
  public GetSearch(name:string)
  {
    return this.http.get(this.APIURL+"search?part=snippet&key="+this.APIKEY+"&q="+name+"&type=video");
  }

  public GetChannel(username:any)
  {
    return this.http.get("https://youtube.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&forUsername="+username+"&key=AIzaSyB40HaKwd0VggftBq8R9sEwQx_NG5xOOWc");  
  }

  public GetVideos()
  {
    return this.http.get("https://youtube.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&chart=mostPopular®ionCode=IN&key=AIzaSyB40HaKwd0VggftBq8R9sEwQx_NG5xOOWc")
  }

  public GetSubscriptions()
  {
    return this.http.get("https://youtube.googleapis.com/youtube/v3/subscriptions?part=snippet%2CcontentDetails&mine=true&key=AIzaSyB40HaKwd0VggftBq8R9sEwQx_NG5xOOWc"),this.reqHeader;
  }
  
  public GetPlaylist(id:any)
  {
    return this.http.get("https://youtube.googleapis.com/youtube/v3/playlists?part=snippet%2CcontentDetails&channelId="+id+"&maxResults=25&key=AIzaSyB40HaKwd0VggftBq8R9sEwQx_NG5xOOWc")
  }
}
Posted
Comments
Member 15670449 12-Jun-22 1:26am    
Download kaise kare
Member 15670449 12-Jun-22 1:27am    
Please Download
Member 15670449 12-Jun-22 1:28am    
File

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900