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

How do i authenticate my Oauth credentials for the youtube API?

$
0
0

I've spend hours going in circles because I can't seem to find whats going wrong on my end. I'm trying to use the youtube api to get information on my videos that I've posted on my channel. However, I can't seem to get past authenticating myself. I'm using Oauth2.0 and I'm like 95% sure I've configured the credentials and consent things on google cloud correctly. I've tried other people's code and all of them give the same error, that I'm missing a valid API key. I have a couple of ideas to why its happening but my main theory is that the api documentation is kinda outdated and so maybe i jumbled up my code. Or im simply not passing the credentials parameter properly.. i have no idea.

    import os    from google.auth.transport.requests import Request    from google.oauth2.credentials import Credentials    from google_auth_oauthlib.flow import InstalledAppFlow    from googleapiclient.discovery import build    from googleapiclient.errors import HttpError    from google.oauth2 import service_account    credentials_file = 'credentials.json'    SCOPES = ['https://www.googleapis.com/auth/youtube.readonly']    def main():        credentials = None        if os.path.exists('token.json'):            credentials = Credentials.from_authorized_user_file('token.json', SCOPES)        if not credentials or not credentials.valid:            if credentials and credentials.expired and credentials.refresh_token:                credentials.refresh(Request())            else:                flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)                credentials = flow.run_local_server(port=8080)            with open('token.json', 'w') as token:                token.write(credentials.to_json())        youtube = build('youtube', 'v3', credentials=credentials)        youtube.search().list(            forMine=True,            type='video',            part='id',            #channelId='left blank for example'         ).execute()    if __name__ == "__main__":        main()

This is the script, i don't think the issue is specific to this script though since the same thing happened when i tried other's.

here is my error:

googleapiclient.errors.HttpError: <HttpError 403 when requesting

heres the message i get in my browser

    {"error": {"code": 403,"message": "The request is missing a valid API key.","errors": [          {"message": "The request is missing a valid API key.","domain": "global","reason": "forbidden"          }        ],"status": "PERMISSION_DENIED"      }``your text``    }`your text`

If anyone has any tips please let me know!


Viewing all articles
Browse latest Browse all 3831

Trending Articles



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