oauth で google plus api 使ってみる。APIs consoleとか

https://developers.google.com/+/api/oauth

https://developers.google.com/accounts/docs/OAuth2#basicsteps

APIs consoleに登録してみる

API Access
To prevent abuse, Google places limits on API requests. Using a valid OAuth token or API key allows you to exceed anonymous limits by connecting requests back to your project.

Authorized API Access
OAuth 2.0 allows users to share specific data with you (for example, contact lists) while keeping their usernames, passwords, and other information private. A single project may contain up to 7 client IDs. Learn more
Branding information
The following information is shown to users whenever you request access to their private data.

Product name: shout.socialic.net
Google account: 000000000000@gmail.com

Edit branding information…

Client ID for web applications
Client ID: 99999999999999.apps.googleusercontent.com
Email address: @developer.gserviceaccount.com
Client secret: xxxxxxxxxxx
Redirect URIs: http://socialic.net/path/to/callback
JavaScript origins: http://socialic.net

で、javascriptからログインしてみる。

https://developers.google.com/accounts/docs/OAuth2UserAgent

サンプルのこれに自分のパラメータを設定して

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&
state=%2Fprofile&
redirect_uri=https%3A%2F%2Foauth2-login-demo.appspot.com%2Foauthcallback&
response_type=token&
client_id=812741506391.apps.googleusercontent.com

開くとcallbackが帰ってくる

http://socialic.net/path/to/callback#state=shout&access_token=ya29.AHES6ZT9fl7me_VHJGhHouamMrxFrEN95SgOPD_h3areEgnJcKRqjw&token_type=Bearer&expires_in=3600

http://www.eisbahn.jp/yoichiro/2011/10/chrome-extension-oauth.html

こちらを参考にさせていただき、#以降を付加してextensionへリダイレクトしてしまいます。

tokeninfoを見てみる。

https://www.googleapis.com/oauth2/v1/tokeninfo?access_token={ACCESS_TOKEN}

にアクセスするだけ。

access_type: “online”
audience: “999999999999.apps.googleusercontent.com”
expires_in: 3599
issued_to: “999999999999.apps.googleusercontent.com”
scope: “https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me”
user_id: “999999999999”

userinfo

family_name: “Otake”
gender: “male”
given_name: “Junichi”
id: “10000000000000”
link: “https://plus.google.com/10000000000000″
locale: “en”
name: “Junichi Otake”
picture: “https://lh5.googleusercontent.com/——–/photo.jpg”

こんな値が返ってきました。

plus / me (https://www.googleapis.com/plus/v1/people/me)のほうは APIs consoleで利用設定をします。

https://developers.google.com/+/api/latest/people/get

aboutMe: “http://groundroad.com


displayName: “Junichi Otake”
etag: “”””
gender: “male”
id: “”
image: Object
url: “https://lh5.googleusercontent.com/———/photo.jpg?sz=50″
__proto__: Object
kind: “plus#person”
name: Object
familyName: “Otake”
givenName: “Junichi”
__proto__: Object
url: “https://plus.google.com/100″
urls: Array[3]

こんな感じのデータが返ってきました。

This entry was posted on 日曜日, 9月 2nd, 2012 at 7:39 PM and is filed under Google, Javascript. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Unityによるゲームを公開しております iOS/Android
https://itunes.apple.com/jp/app/lost-knight-3d-action/id900917032
https://play.google.com/store/apps/details?id=com.groundroad.runknight

各種開発支援・機能開発等小さいお仕事などもお請けしております。
unity開発支援, PHPシステム開発, javascript/html5 フロント開発, titanium mobileアプリ開発
お気軽にお問い合わせください
大崎・五反田近郊での対面でのお打ち合わせはいつでも可能です。