首页 > 解决方案 > OAuthException 191 问题:无法加载 URL

问题描述

我遇到了使用 OAuthException 191 登录 Facebook 的问题,如图所示,将重定向 URI 显示为“ http://zsize.openservice.or.th/callback/facebook”“OAuthException 191 - 无法加载 URL:此 URL 的域未包含在应用程序的域中

我认为有效 OAUTH 重定向 URI 出了点问题。但是,当我如下图所示检查了我的 Facebook API 的有效 OAUTH 重定向 URI 部分时,它已显示为由重定向 URI 验证器验证的“ h​​ttps://zsize.openservice.or.th/callback/facebook ”

有效的 OAUTH 重定向 URI

这真的让我很困惑,因为我虽然已经将 OAUTH 重定向 URI 更改为“https://”,但页面上显示“OAuthException 191”的链接仍然将重定向 URI 显示为“http://”。如何处理这种错误?请帮我。

哦,顺便说一句,与 Facebook 登录相关的代码在这里:

授权给提供者:

@app.route('/authorize/<provider>',methods=['GET','POST'])
 def oauth_authorize(provider):
    try:
        oauth = OAuthSignIn.get_provider(provider)
        except ValueError:
            return "Authorize Failure"
        return oauth.authorize()
@app.route('/callback/<provider>',methods=['GET','POST'])
 def oauth_callback(provider):
        if not current_user.is_anonymous:
            return redirect(url_for('timeline'))

回调提供者:

@app.route('/callback/<provider>',methods=['GET','POST'])
def oauth_callback(provider):
    if not current_user.is_anonymous:
        ###print('Error - The current user is not anonymous','danger') 
        return redirect(url_for('timeline'))

    ###print('Start Callback sign in to Provider','info')  

    try: 
        oauth = OAuthSignIn.get_provider(provider) # problem arrise 
        social_id1, username1, email1, first_name1, last_name1, name1, gender1, profile_url1= oauth.callback()
    except ValueError:
        return render_template('index.html',error="callback failure")
    except OAuthCallbackError as e:
        return render_template('index.html',error=e.errors['error_code'] +" " +e.errors['error']+" : " +e.errors['error_description'])

    if email1 is None:
        email1 = ""


        if db.getUserbySocialID(social_id1).get("id") is None: # if never login by this social account
            db.regisUserSocial(social_id1, email1, datetime_now())

        user = User(social_id = social_id1)

        ImageDirectory = app.config['USER_IMAGE_DIRECTORY']
        SocialIDString = str(social_id1)
        CheckString = SocialIDString[0:6]

        ImageFilename = str(username1) + '.jpg'
        ImageFullDirectoryGlobal = ImageFilename
        ImageURL = str(profile_url1)
        r = requests.get(ImageURL) 
        if CheckString == 'facebo':
            dirname = "FaceBook"
        elif CheckString == 'google':
            dirname = "Google"
        SocialDirectory = dirname + SocialIDString[9:]
        ImageSocialDirectoryGlobal = SocialDirectory
        UserImageDirectory = ImageDirectory+SocialDirectory
        UserImageDirectory = UserImageDirectory + '/'
        ImageFullDirectoryGlobal = UserImageDirectory 
        if not os.path.exists(UserImageDirectory):
            os.makedirs(UserImageDirectory)  
        ImageFullFilename = UserImageDirectory + ImageFilename
        ImageFullFilenameGlobal = ImageFullFilename

        with open(ImageFullFilename, 'wb') as f:
            f.write(r.content) 
        ParsingImageDirectory = '../'+ImageDirectory 
        ParsingImageFile = ParsingImageDirectory + 
ImageSocialDirectoryGlobal
        ParsingImageFile = ParsingImageFile + '/'
        ParsingImageFile = ParsingImageFile + ImageFilename

        # TODO remove session
        login_user(user)
        current_user.logintype = "social"
        current_user.confirmed = True

        session['imglocation'] = ParsingImageFile +"?"+ 
        str(datetime.datetime.now().strftime('%d%m%y%H%M%S%f'))
        session['username'] = username1
        session['nickname'] = name1
        session['logged_in'] = True
        session['logged_by'] = 'social'
        session['confirmed'] = True
        session['email'] = current_user.email
        return redirect(url_for('timeline'))

如果您能找到此 OAuthException 191 的解决方案,请帮助我:

标签: facebookapioauth-2.0

解决方案


推荐阅读