Merhaba Visual Studio 'da bir python kodu çalıştırmaya çalışıyorum, Kod aşağıda, işlevi ise bir Youtube giriş butonu ile "
Login with YouTube " youtube 'da yaptığı canlı yayını kendi sitende yayınlama aracı olurşturmak .Local'de çalıştığı için Google Console daki ayarları "http://localhost:5000/oauth2callback" olarak düzenledim ama "Missing required parameter: redirect_uri " hatasını alıyorum ve bunu aşamadım yardımcı olabilecek bir babayiğit var mı ?
Kod :
from flask import Flask, redirect, url_for, session, Response, request
from authlib.integrations.flask_client import OAuth
import os
import cv2
from google_auth_oauthlib.flow import Flow # Flow sınıfını içe aktar
app = Flask(__name__)
app.secret_key = os.urandom(24)
oauth = OAuth(app)
# Google OAuth 2.0 istemcisini oluştur
CLIENT_SECRETS_FILE = "client_secret.json"
SCOPES = ['https://www.googleapis.com/auth/youtube.readonly']
flow = Flow.from_client_secrets_file(CLIENT_SECRETS_FILE, scopes=SCOPES)
# Yetkilendirme URL'sini al
auth_url, _ = flow.authorization_url(access_type='offline', include_granted_scopes='true')
# YouTube ile OAuth 2.0 kimlik doğrulama sağlayıcısı oluştur
youtube = oauth.register(
name='youtube',
client_id='431111917939-j2l2kf0dihd3trq4bbi5eqbc0eom6ii6.apps.googleuserco ntent.com',
client_secret='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',
authorize_url='https://accounts.google.com/o/oauth2/auth',
authorize_params={'scope': 'https://www.googleapis.com/auth/youtube.readonly'},
access_token_url='https://accounts.google.com/o/oauth2/token',
access_token_params=None,
refresh_token_url=None,
refresh_token_params=None,
redirect_uri='http://localhost:5000/oauth2callback',
client_kwargs={'access_type': 'offline'}
)
@app.route('/')
def index():
return f'<a href="{auth_url}">Login with YouTube</a>'
@app.route('/oauth2callback')
def oauth2callback():
flow.fetch_token(authorization_response=request.ur l)
credentials = flow.credentials
session['credentials'] = {
'token': credentials.token,
'refresh_token': credentials.refresh_token,
'token_uri': credentials.token_uri,
'client_id': credentials.client_id,
'client_secret': credentials.client_secret,
'scopes': credentials.scopes
}
return redirect(url_for('video_feed'))
@app.route('/video_feed')
def video_feed():
credentials = session.get('credentials')
if credentials is None:
return redirect(url_for('index'))
# Kullanıcının giriş yaptığı URL'yi alın
youtube_url = request.url
# Kullanıcının giriş yaptığı URL'yi kullanarak gerçek YouTube canlı yayın URL'sini oluşturun
youtube_url_with_token = youtube_url # Eğer 'append_access_token_to_url' fonksiyonunu tanımlamadıysanız
return Response(generate_frames(youtube_url_with_token),
mimetype='multipart/x-mixed-replace; boundary=frame')
# YouTube canlı yayınını web'e yayınla
def generate_frames(youtube_url):
video = cv2.VideoCapture(youtube_url)
while True:
success, frame = video.read()
if not success:
break
else:
ret, buffer = cv2.imencode('.jpg', frame)
frame = buffer.tobytes()
yield (b'--framern'
b'Content-Type: image/jpegrnrn' + frame + b'rn')
if __name__ == '__main__':
app.run(debug=True, use_reloader=False)