一个帮助将googleoauth2.0集成到Django应用程序的库。
google-apis-oauth-django的Python项目详细描述
谷歌API OAuth Django
{a2}
一个帮助将googleoauth2.0集成到Django应用程序的库。此库检索访问应用程序配置的googleapi所需的必要令牌。在
安装
pip install google-apis-oauth-django
使用
将用户重定向到登录屏幕
^{pr2}$成功登录后重新审阅和存储凭据
importgoogle_apis_oauthdefRedirectView(request):try:# Get user credentialscredentials=google_apis_oauth.get_crendentials_from_callback(request,JSON_FILEPATH,SCOPES,REDIRECT_URI)# Stringify credentials for storing them in the DBstringified_token=google_apis_oauth.stringify_credentials(credentials)# Store the credentials safely in the DB...# Now that you have stored the user credentials you# can redirect user to your main application....exceptgoogle_apis_oauth.exceptions.InvalidLoginException:# Handle unauthenticated request to the callback uri.
加载和使用用户凭据
importgoogle_apis_oauthfromgoogleapiclient.discoveryimportbuild# Use the stringified token to get a credentials object# that can be used to authenticate requests made by# google-api-python-client# NOTE: This function automatically refreshes the access_token# if required.creds=google_apis_oauth.load_credentials(stringified_token)# Using credentials in google-api-python-client.service=build('calendar','v3',credentials=creds)...
示例
您可以参考this博客以获取使用此库的示例。在
- 项目
标签: