I can't get permission. This error comes out. What to do?
I called the get_user_info
function by passing the user's primary key and its token in arguments. Then, in the get_user_info
function, the get_service
function is called to gain access to the user's YouTube account. The problem occurs when I try to redirect the user to a page with permission to get information about his account.
TOKEN_FILE = json.dumps(GlobalSettings.objects.first().secret_token)APP_TOKEN_FILE = json.loads(TOKEN_FILE)SCOPES = ["https://www.googleapis.com/auth/youtube.readonly"]def get_creds_saved(current_user_pk, USER_TOKEN): creds = None if USER_TOKEN is not None: creds = Credentials.from_authorized_user_info(USER_TOKEN, SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: flow = InstalledAppFlow.from_client_config(APP_TOKEN_FILE, SCOPES) flow.redirect_uri = 'https://oxy-cash.ru/earnmoney/' authorization_url, state = flow.authorization_url( access_type='offline', include_granted_scopes='true') return redirect(authorization_url) # user = CustomUser.objects.get(pk=current_user_pk) # user.user_token = creds.to_json() # user.save() return credsdef get_service(current_user_pk, USER_TOKEN): creds = get_creds_saved(current_user_pk=current_user_pk, USER_TOKEN=USER_TOKEN) service = build('youtube', 'v3', credentials=creds) return servicedef get_user_info(current_user_pk, USER_TOKEN): channel = get_service(current_user_pk=current_user_pk, USER_TOKEN=USER_TOKEN).channels().list(part="snippet,contentDetails,statistics", mine=True).execute() info = {'username': channel['items'][0]['snippet']['title'],'photo': channel['items'][0]['snippet']['thumbnails']['default']['url'] } return infodef app_earnmoney(request): if request.user.is_authenticated: current_user = CustomUser.objects.get(pk=request.user.pk) is_next_day(current_user) info = get_user_info(current_user_pk=request.user.pk, USER_TOKEN=current_user.user_token)