YouTube Data API v.3.0 Unable to Add/Delete Video from Playlist - InsufficientPermissions Exception

StackOverflow https://stackoverflow.com/questions/23500797

  •  16-07-2023
  •  | 
  •  

Question

All day long I'm trying to delete/add video to my YouTube playlists. I'm using the YouTube Data API v.3.0. for .NET C#. I have already created a project in Google Developer Console and got my client secrets JSON file. Also my code for obtaining list items is working ok which means that only the PUT operations are not working as expected. I have used almost the same code as in the google developers site code examples.

Authentication method:

 private async Task<YouTubeService> GetYouTubeService(string userEmail)
    {
        UserCredential credential;
        using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
        {
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                new[]
                { 
                    YouTubeService.Scope.Youtube,
                    YouTubeService.Scope.Youtubepartner,
                    YouTubeService.Scope.YoutubeUpload,
                    YouTubeService.Scope.YoutubepartnerChannelAudit, 
                    YouTubeService.Scope.YoutubeReadonly 
                },
                userEmail,
                CancellationToken.None,
                new FileDataStore(this.GetType().ToString()));
        }

        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = this.GetType().ToString()
        });

        return youtubeService;
    }

Add video to playlist code:

  private async Task AddSongToPlaylistAsync(string userEmail, string songId, string playlistId)
    {
        var youtubeService = await this.GetYouTubeService(userEmail);
        var newPlaylistItem = new PlaylistItem();
        newPlaylistItem.Snippet = new PlaylistItemSnippet();
        newPlaylistItem.Snippet.PlaylistId = playlistId;
        newPlaylistItem.Snippet.ResourceId = new ResourceId();
        newPlaylistItem.Snippet.ResourceId.Kind = "youtube#video";
        newPlaylistItem.Snippet.ResourceId.VideoId = songId;
        newPlaylistItem = await youtubeService.PlaylistItems.Insert(newPlaylistItem, "snippet").ExecuteAsync();
    }

this is the message that I receive when I try to add a new video to the specified playlist:

Google.Apis.Requests.RequestError Insufficient Permission [403] Errors [ Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global] ]

I'll really appreciate any available help because I didn't find anything useful googling. Thank you in advance!

Was it helpful?

Solution

I encountered the same issue but if anyone is having issue with the inefficient permission when adding a video to a playlist, you will need to have the YouTubeService.Scope.Youtube (which looks like you already have).

var scopes = new[]
{
    YouTubeService.Scope.Youtube
};

If you however added the scope after you already have given the permission, you will need to revoke the client by going to this page manage permissions. You will have to look for your specific client. After you've done that, you can rerun you app and request for permission once again.

Another option is to create a new clientId and clientSecret again and make sure you have the right scope to begin with. I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top