#API request to for YouTube comments not returning :ok tuples

5 messages · Page 1 of 1 (latest)

magic creek
#

I'm using the google_api_you_tube library to search for YouTube videos, then use the videoIds to request the comment threads, and then finally extracting the comments from the maps.

{:ok, videos} = Search.youtube_search_list(search_conn, ["snippet"], [{:key, @api_key}, {:q, "cats"}])

comment_threads = Enum.map(videos.items, fn video -> CommentThreads.youtube_comment_threads_list(search_conn, ["snippet"], [{:key, @api_key}, {:videoId, video.id.videoId}, {:maxResults, 2}]) end)
    
comments = Enum.map(comment_threads.items, fn comment_thread -> extract_comments(comment_thread) end)

My issue is that when I inspect comment_threads it looks like this:

comment_threads: [
  ok: %GoogleApi.YouTube.V3.Model.CommentThreadListResponse{
    visitorId: nil,
    tokenPagination: nil,
    pageInfo: %GoogleApi.YouTube.V3.Model.PageInfo{
      totalResults: 2,
      resultsPerPage: 2
    },
    ... ,
ok: %GoogleApi.YouTube.V3.Model.CommentThreadListResponse{
    visitorId: nil,
    tokenPagination: nil,
    pageInfo: %GoogleApi.YouTube.V3.Model.PageInfo{
      totalResults: 2,
      resultsPerPage: 2
    },

These are not tuples. Is there something I'm doing wrong to make it not return as tuples? And if not, is there a way to pattern match to remove the ok: on each list element? I have tried but been implementing it incorrectly.

gilded flame
#

Welcome to the wide and awful world of google's elixir APIs.
You're receiving a list of OK tuples for some reason. It's printing out like a keyword list.

sharp pagoda
magic creek
#

I didn't understand what keyword lists were before, I see what's going on now.

gilded flame