0

For some reason, my resource "youtube_client" doesnt recognize the method "videos()". What could be some possible reasons for this error message? I imported the needed youtube libraries.

Upon request here is a fuller view of the problem. You can see All the libraries included and the problem is happening after step 2 : request = self.youtube_client.videos().list(

update: the error says: Instance of 'Resource' has no 'videos' member pylint(no-member)

import json
import os  

import google_auth_oauthlib.flow
import googleapiclient.discovery  # youtube APIv3
import googleapiclient.errors

import requests
import youtube_dl

# takes the variable we want from secret file
from secret import spotify_user_id, spotify_token


class CreatePlaylist:

    def __init__(self):  
        self.user_id = spotify_user_id  # takes the username in our secret file
        self.spotify_token = spotify_token
        self.youtube_client = self.get_youtube_client()
        self.all_song_info = {}

    # STEP 1: Sign into youtube  
    def get_youtube_client(self):
        # COPIED FROM YOUTUE DATA API
        # Disable OAuthlib's HTTPS verification when running locally.
        # *DO NOT* leave this option enabled in production.
        os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

        api_service_name = "youtube"
        api_version = "v3"
        client_secrets_file = "client_secret.json"  # this is MY special id number

        # Get credentials and create an API client
        scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
        flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
            client_secrets_file, scopes)
        credentials = flow.run_console()

        # From YOUTUBE_API
        youtube_client = googleapiclient.discovery.build(
            api_service_name, api_version, credentials=credentials)

        return youtube_client

    # STEP 2: grab like song on youtube // and create a dictionary of important song info
    def get_liked_videos(self):  
        request = self.youtube_client.videos().list(
            part="snippet,contentDetails,statistics",
            myRating="like"
        )
        response = request.execute()

        # collect each video and get important info #loops through all song called item
        for item in response["items"]:
            video_title = item["snipped"]["title"]
            # plug in URL HERE (not done)
            youtube_url = "https://www.youtube.com/watch?v={}".format(
                item["id"])

            # use youtube_dl lib to collect the song name and artist
            video = youtube_dl.YoutubeDL({}).extract_info(
                youtube_url, download=False)

            song_name = video["track"]
            artist = video["artist"]

            # save imported information
            self.all_song_info[video_title] = {
                "youtube_url": youtube_url,
                "song_name": song_name,
                "artist": artist,

                # add the uri, easy to get song to put into Playlist
                # call the function we wrote
                "spotify_uri": self.get_spotify_uri(song_name, artist)
            }
stvar
  • 6,551
  • 2
  • 13
  • 28
Jane
  • 23
  • 6
  • 1
    Do post an entire source code context, including imports. – stvar Jul 22 '20 at 06:59
  • 1
    Also please post (as text) the exception messages that you obtained. I suspect that `youtube_client` is not initialized properly (maybe because of failed OAuth flow). – stvar Jul 23 '20 at 10:17
  • added the stuff you requested! – Jane Jul 25 '20 at 01:21
  • Do the answers to [this question](https://stackoverflow.com/q/56844378/8327971) help you? Note that each and every API endpoint method under the object `youtube_client` is generated at run-time. That's why `pylint` is complaining. – stvar Jul 25 '20 at 21:24
  • @stvar Thank you for your resource! It does appear to have fixed that error. Thank you! However when I'm given the URL to verify my google account, it lets me almost login but then crashes and says "this app isnt verified". I looked into it, seems like it could be a scope issue? Do you have any suggestions? This is all still very new to me so any advice would help. – Jane Jul 25 '20 at 23:06
  • Read the official support doc [Unverified apps](https://support.google.com/cloud/answer/7454865), specifically the section [Unverified app screen](https://support.google.com/cloud/answer/7454865#unverified-app-screen). – stvar Jul 25 '20 at 23:13
  • Another good source of info: [OAuth Client Verification](https://developers.google.com/apps-script/guides/client-verification). Basically, you don't need to get your app verified by Google while still developing it. Do click 'Advanced', then click 'Go to ... (unsafe)'. – stvar Jul 25 '20 at 23:29

0 Answers0