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

Requires Scope Authentication on using Youtube API

$
0
0

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.

Subscription.ts file

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&regionCode=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");  }  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")  }}

Error Message:403-Forbidden error


Viewing all articles
Browse latest Browse all 3638

Trending Articles



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