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

Youtube Data API 3 key not valid

$
0
0

I'm developing a window form software that retrieve the first video result ID given a qwery.I then, want to add it to a specific playlist.The code I'm using is:

Imports SystemImports System.Collections.GenericImports System.IOImports System.NetImports System.ReflectionImports System.TextImports System.ThreadingImports System.Threading.TasksImports Google.Apis.Auth.OAuth2Imports Google.Apis.ServicesImports Google.Apis.UploadImports Google.Apis.Util.StoreImports Google.Apis.YouTube.v3Imports Google.Apis.YouTube.v3.DataPublic Class Form1    Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click        Try            Await Run()        Catch ex As AggregateException            For Each inner In ex.InnerExceptions                MsgBox("Error: " & inner.Message)            Next        End Try    End Sub    Private Async Function Run() As Task        Dim youtubeService = New YouTubeService(New BaseClientService.Initializer() With {            .ApiKey = "AIzaSyCuYBXFeEMnUmWqvVqS3hm0dgl8HhmmdMk",            .ApplicationName = Me.[GetType]().ToString()        })        Dim credential As UserCredential        Using stream = New FileStream("secret.json", FileMode.Open, FileAccess.Read)            credential = Await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.FromStream(stream).Secrets, {YouTubeService.Scope.Youtube}, "user", CancellationToken.None, New FileDataStore(Me.[GetType]().ToString()))        End Using        Dim searchListRequest = youtubeService.Search.List("snippet")            searchListRequest.Q = TextBox1.Text        searchListRequest.MaxResults = 1        Dim searchListResponse = Await searchListRequest.ExecuteAsync()        Dim videos As List(Of String) = New List(Of String)()        Dim channels As List(Of String) = New List(Of String)()        Dim playlists As List(Of String) = New List(Of String)()        For Each searchResult In searchListResponse.Items            videos.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.VideoId))        Next        MsgBox(String.Format("Videos:" & vbLf & "{0}" & vbLf, String.Join(vbLf, videos)))        Dim newPlaylistItem = New PlaylistItem()        newPlaylistItem.Snippet = New PlaylistItemSnippet()        newPlaylistItem.Snippet.PlaylistId = "FLWDmLq6_dhJKcaDWFz4hD4g"        newPlaylistItem.Snippet.ResourceId = New ResourceId()        newPlaylistItem.Snippet.ResourceId.Kind = "youtube#video"        newPlaylistItem.Snippet.ResourceId.VideoId = "GNRMeaz6QRI"        newPlaylistItem = Await youtubeService.PlaylistItems.Insert(newPlaylistItem, "snippet").ExecuteAsync()        Console.WriteLine("Playlist item id {0} was added to playlist id {1}.", newPlaylistItem.Id, "FLWDmLq6_dhJKcaDWFz4hD4g")    End FunctionEnd Class

I ve enabled the API's and add all youtube scopes. I've tried to save the API key and the secret OAuth2.

but during debug I'm getting an issue

" The service YouTube as thrown an exception. HttpStatusCode isUnauthorize. APi keys are not supported by this API. Expected OAuth 2access token or other authentication credentials that assert aprincipal".

I went on youtube to check for tutorials and I did everything they suggest, bus I still having this issue. So, i recorder a long gif where I'm starting a new fresh project on google console, enabling the youtube api and collecting the credentials, downloading the json, renaming it as secret and saving it into the debug folder of my vb.net project. The API keys and the OAuth code Im using are only for test, so I don't need to remove them from the video/question.

video here

Can someone point me where I'm doing wrong ? thanks


Viewing all articles
Browse latest Browse all 3637

Trending Articles