Facebook APIを使って、コマンドラインから JSON形式のデータを取得してみる
上記の記事を参考に Google+ API での JSON 取得をやってみた。
クライアントの登録
- Google+ にログインした状態で https://console.developers.google.com/project を開き、 Create Project からプロジェクトを作成する。
- 作成されたら APIs & auth の APIs から Google+ API を有効にする。
- APIs & auth の Credentials から Create new Client ID でクライアント ID を作成。
- Application Type = Web application
- Authorized redirect URIs = http://localhost/
- 作成された Client ID と Client secret を控えておく。
aurl
aurl は元記事で導入されているものとします。
-
~/.aurl/profiles を編集する。
[google] client_id = 前節で控えておいた Client ID client_secret = 前節で控えておいた Client secret auth_server_auth_endpoint = https://accounts.google.com/o/oauth2/auth auth_server_token_endpoint = https://accounts.google.com/o/oauth2/token redirect = http://localhost/ scopes = https://www.googleapis.com/auth/plus.login
-
コマンドを実行する。
$ aurl --profile google get https://www.googleapis.com/plus/v1/people/me
-
以下のようなメッセージが表示されて入力待ちとなるので、ブラウザで URL を開き承認する。
Open https://accounts.google.com/o/oauth2/auth?(省略) and get code Enter code:
-
承認後にリダイレクトされた URL から
code=
を抽出し、入力待ちとなっていたコンソールに入力する。{ "kind": "plus#person", "etag": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "gender": "male", "objectType": "person", "id": "XXXXXXXXXXXXXXXXXXXXX", "displayName": "Taichi Sasaki", "name": { "familyName": "Sasaki", "givenName": "Taichi" }, "url": "https://plus.google.com/XXXXXXXXXXXXXXXXXXXXX", "image": { "url": "https://lh3.googleusercontent.com/XXXXXXXXXXXX/XXXXXXXXXXX/XXXXXXXXXXX/XXXXXXXXXXX/photo.jpg?sz=XX", "isDefault": true }, "isPlusUser": true, "language": "ja", "ageRange": { "min": XX }, "circledByCount": 0, "verified": false }
取れた!
あとがき
元記事が非常にわかりやすかったので Goole+ でも簡単に出来ました。感謝です。