简体   繁体   English

Facebook API Auth 2 与 python 或 Django

[英]Facebook API Auth 2 with python or Django

I am trying ti get user Token using Facebook oauth2 api but i am facing this error when redirect url call.我正在尝试使用 Facebook oauth2 api 获取用户令牌,但我在重定向 url 调用时遇到此错误。

InsecureTransportError at /data/FacebookAuth/ (insecure_transport) OAuth 2 MUST utilize https. InsecureTransportError at /data/FacebookAuth/ (insecure_transport) OAuth 2 必须使用 https。

I have running ngrok & https setup but i can't figure out why it is giving me this error我已经运行 ngrok & https 设置,但我不知道为什么它给了我这个错误

Here is my code to get this token in django这是我在 django 中获取此令牌的代码

#Facebook App Credentials
client_id = 'xxxx'
client_secret = 'xxxxx'

# OAuth endpoints given in the Facebook API documentation> 

authorization_base_url = 'https://www.facebook.com/dialog/oauth'
token_url = 'https://graph.facebook.com/oauth/access_token'
redirect_uri = 'https://ab207c1f.ngrok.io/data/FacebookAuthRedirect' 

facebook = OAuth2Session(client_id, redirect_uri=redirect_uri)
facebook = facebook_compliance_fix(facebook)

#Getting Facebook Authentication
def FacebookAuth(request): 
    authorization_url, state = facebook.authorization_url(authorization_base_url)   
    redirect(authorization_url)

#Getting Facebook Authentication Redirect

def FacebookAuthRedirect(request):
    redirect_response = request.GET.get('code', '')
    token = facebook.fetch_token(token_url, client_secret=client_secret,
                   authorization_response=redirect_response)   
    print(token)
    return HttpResponse('ibrahim')

After digging a bit.挖了一点之后。 I found a solution that worked for me.我找到了一个适合我的解决方案。

it was because of authorization_code = request.build_absolute_uri() .这是因为authorization_code = request.build_absolute_uri() I tried printing it and it contained "http" instead of "https" .我尝试打印它,它包含"http"而不是"https" I replaced the string with https using the following code.我使用以下代码将字符串替换为https redirect_response = redirect_response.replace("http://", "https://")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到所需的Django Facebook Python软件包的身份验证后端 - Required auth backend for Django Facebook Python package wasn't found Django-python-social-auth:Facebook返回匿名用户 - Django - python-social-auth: Facebook returns anonymous user 使用Facebook登录名的Django Rest Auth? - Django Rest Auth with Facebook login? Python社交身份验证-Facebook-Django:如何获取和使用Facebook的用户链接属性? - Python Social Auth - Facebook - Django: How do I obtain and use the users link attribute for Facebook? Python JWT身份验证令牌未使用django jwt api授权 - Python JWT auth token does not authorize with django jwt api django:Facebook注册API的rest-auth和allauth需要CSRF令牌 - django: rest-auth and allauth for Facebook registration API requires CSRF token Python Tornado Facebook身份验证错误 - Python Tornado Facebook Auth Error 数据狗 API python 身份验证 - datadog API python auth 如何使用Python-Social-auth和Django检索Facebook好友的信息 - How to retrieve Facebook friend's information with Python-Social-auth and Django Django中的Python社交身份验证可使用应用程序访问令牌将URL发布到我的业务Facebook页面 - Python social auth in django to post URL to my business Facebook page using application access token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM