College Project - Youtube Auto-Replier - Google API

59 Views Asked by At

I'm developing a project for college, something like an AI that reads the comments, writes a reply based on the user's comment and then replies to them.

I had no issues with the comment part where the API gets the comments and ChatGPT generates a response to it (although I had to write a large complex prompt for it to work), but replying requires an authentication that I'm pretty sure I have - It's a JSON file that I get from console.cloud.google.com/apis/credentials on the OAuth 2.0 part.

That's my current code:

import googleapiclient.discovery
import openai
import json
from google.oauth2.credentials import Credentials

with open('C:\Users\Name\Downloads\token.json') as f:
info = json.load(f)

creds = Credentials.from_authorized_user_info(info)
youtube = googleapiclient.discovery.build('youtube', 'v3', credentials=creds)

I get error code:

ValueError: Authorized user info was not in the expected format, missing fields refresh_token

I searched for how to get that token but am unable to find anything related to it that could be applied to that .json, that's the code I have there:

{"client_id":"Censored","project_id":"serene-mender","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"Censored","redirect_uris":["http://localhost"]}

I've tried searching a lot for it on Google, Discord Dev servers and Reddit, but couldn't find anything that really helped with it, as it seems to be extremely rare to use this function (reply/delete comments) and I found no examples.

0

There are 0 best solutions below