一大坨GoogleAPI的学习笔记之一(oAuth2.0)

Posted on 2013-07-30 19:10  冰天雪域  阅读(362)  评论(0编辑  收藏  举报

官方文档地址:https://developers.google.com/accounts/docs/OAuth2InstalledApp

最近Ubuntu下VGA接口无端的不能用了,木有心情翻译了,就大体看了看。

这是关于本地应用的部分。

首先申请一个clent ID之类的东西:


因为要做的是一个Linux上的Python应用,所以type应该是其他。

申请之后的效果是这样的:


应用可以用一个按钮来打开授权页面,授权页面的网址应该是这样的:

 

"""
https://accounts.google.com/o/oauth2/auth?
scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&
redirect_uri=http://localhost:8888&
response_type=code&
client_id=你的ID
"""

其中ClientID就是你应用的ID,RedirectURLs是用户点击授权按钮后重新定向到的网址。用户在浏览器打开该URL后会显示这样一个页面,如果用户点击接受就会重定向到redirect_uri指向的地址

 

为了看看效果我使用webpy来接受这个请求,其代码如下:

 

import web

urls = (
    '/', 'oauth'
)

class oauth:
    def GET(self):
	data = web.input()
	return data

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()


授权成功后

 


然后就可以使用那个奇怪的乱码调用GoogleAPI了。


 

Copyright © 2024 冰天雪域
Powered by .NET 8.0 on Kubernetes