一个帮助将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博客以获取使用此库的示例。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java是从此类字符串中提取数据的最佳方法   filenotfoundexception Java FileOutputStream Windows/Linux   java在SQLite数据库Android SDK中搜索特定字符串   java使用键值访问jsp中Map<Long,Map<String,Object>>的内容   java奇怪的HTMLeditor工具包问题   在java中使用数组只计算字母   每个应用程序都可以有自己独立的Java SDK吗   java如何将jasper报告生成的PDF文件保存在一个项目文件夹中   java BigDecimal包装器:静态字段为零   解码Base64图像时出现java IllegalArgumentException(非法的Base64字符)   将int转换为字节在Java和Actionscript中产生不同的结果   java什么使不可变对象在没有安全发布技术的情况下发布?   java将字节数据写入目录   一个计算器中有多个操作的java问题   面向对象Java重写是如何工作的   带hibernate的java ClassCastException   指向最后一个对象的java对象列表   java单元测试spring项目中的Get请求