LoginSignup
0
0

More than 5 years have passed since last update.

Google+ APIを使って、コマンドラインから JSON形式のデータを取得してみる

Posted at

Facebook APIを使って、コマンドラインから JSON形式のデータを取得してみる

上記の記事を参考に Google+ API での JSON 取得をやってみた。

クライアントの登録

  1. Google+ にログインした状態で https://console.developers.google.com/project を開き、 Create Project からプロジェクトを作成する。
  2. 作成されたら APIs & auth の APIs から Google+ API を有効にする。
  3. APIs & auth の Credentials から Create new Client ID でクライアント ID を作成。
  4. 作成された Client ID と Client secret を控えておく。

aurl

aurl は元記事で導入されているものとします。

  1. ~/.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
    
  2. コマンドを実行する。

    $ aurl --profile google get https://www.googleapis.com/plus/v1/people/me
    
  3. 以下のようなメッセージが表示されて入力待ちとなるので、ブラウザで URL を開き承認する。

    Open https://accounts.google.com/o/oauth2/auth?(省略) and get code
    Enter code:
    
  4. 承認後にリダイレクトされた 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+ でも簡単に出来ました。感謝です。

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