LoginSignup
0
0

More than 5 years have passed since last update.

[google-oauth] ユーザー情報取得

Last updated at Posted at 2016-09-18

APIでユーザー情報取得するまでの流れをやってみた

from oauth2client.client import flow_from_clientsecrets
from apiclient.discovery import build
import webbrowser
import httplib2
flow = flow_from_clientsecrets('./oauth2.json',
                                scope='openid',
                                redirect_uri='http://localhost:8080')
url_l = flow.step1_get_authorize_url()
webbrowser.open(url_l)

## ブラウザに表示されているURLのcode=###をコピー

code = '######'
cre = flow.step2_exchange(code)
http = cre.authorize(httplib2.Http())
service = build('oauth2','v2',http=http)
a = service.userinfo().get().execute()

aがユーザー情報を持っているのを確認したので一段落。
buildで作ったResourceオブジェクトのインスタンスは、executeしないと動かないのね。
内部で何やってるのか知らないけど、静的に関数保有してないみたいで
iPython使ってたのに候補が出てこなかった。
次はユーザー管理方法とログアウト制御方法だなー。

ローカルでデータ処理するだけのプログラムに比べると
なんでこう、Webアプリってのは面倒なんだ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0