Scope Authentication Required for Youtube API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pooja2202
    New Member
    • Feb 2022
    • 1

    Scope Authentication Required for Youtube API

    While using the youtube API to get the subscriptions,l iked 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.

    Service.ts:

    Code:
    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 GetSubscriptions()
      {
        return this.http.get("https://youtube.googleapis.com/youtube/v3/subscriptions?part=snippet%2CcontentDetails&mine=true&key=AIzaSyB40HaKwd0VggftBq8R9sEwQx_NG5xOOWc",this.reqHeader);
      }
      
    }
    Error Message:
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32656

    #2
    As someone who knows little about the programming language you're using I've had to guess where to move this thread to. Feel free to report this post with an indication of the appropriate destination if I have it wrong & someone should get it moved for you.

    What I AM positive about is that technical threads of any variety are not appropriate in the Lounge. I'm not sure why the name wasn't enough to make that clear but I hope it is now.

    Comment

    • GazMathias
      Recognized Expert New Member
      • Oct 2008
      • 228

      #3
      Hi NeoPa,

      This is TypeScript (which 'compiles' to Javascript).

      To the OP - only tips I can give you are to inspect your values to ensure they are correct and verify your code is sound when compared to the requirements of the API documentation. If they have a testing server and API with examples then try them first and adapt your strategy,

      Gaz

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32656

        #4
        Thanks for that Gaz. Duly moved :-)

        Comment

        • rishabhs
          New Member
          • Feb 2022
          • 1

          #5
          Great! this is helpful, thanks for sharing.

          Comment

          Working...