Я пытаюсь получать отчеты с помощью YouTube Analytics API, но 403 запрещено меня сбивает. Я много ищу в Google, но не нашел подходящего решения. Я пробую код из его официальных документов с google oAuth 2.0.
import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
def main():
# 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 = "youtubeAnalytics"
api_version = "v2"
client_secrets_file = "YOUR_CLIENT_SECRET_FILE.json"
# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
credentials = flow.run_console()
youtube_analytics = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
request = youtube_analytics.reports().query(
dimensions="day",
endDate="2018-12-01",
ids="channel==UCzxqTj9GZVeSy_Er9VPvKEQ",
metrics="views",
startDate="2018-11-29"
)
response = request.execute()
print(response)
if __name__ == "__main__":
main()
Error
{
"error": {
"code": 403,
"message": "Forbidden",
"errors": [
{
"message": "Forbidden",
"domain": "global",
"reason": "forbidden"
}
]
}
}