我正在尝试制作用于youtube实时聊天的聊天机器人(liveChat v3 API / Youtube Data API)。我使用下面的代码来监听用户聊天消息,从而触发ca。每秒一次。这样做,大约5分钟后我便达到了每日配额上限(上限为8000(重量,不必致电)。如何在没有超出配额限制的情况下以合理的机会实现聊天机器人?
我已经申请了更多配额,不确定是否会给予配额。
是否可以将notes.expired()步骤作为问题的一部分?
try:
from .credentials import Credentials
except:
from credentials import Credentials
nextPageToken = ''
while not self.stopped:
# Make sure access token is valid before request
# credentials.read() should refresh the token automatically
if self.credentials.expired() or token_str == '':
token_str = self.credentials.read()
payload = {'liveChatId': self.liveChatID,
'part': 'snippet,authorDetails',
'pageToken': nextPageToken}
url = 'https://content.googleapis.com/youtube/v3/liveChat/messages'
headers = {"Authorization": "Bearer " + token_str}
r = requests.get(url, headers=headers, params=payload)
if (r.status_code == 200):
resp = r.json()
nextPageToken = resp["nextPageToken"]
msgs = resp["items"]
for msg in msgs:
print(msg)
delay = resp['pollingIntervalMillis']/1000