_RJ 技術メモ

人生を豊かにする技術を提供する、筋肉

Google Slides APIを試す

googleapi googleSlidesAPI

1. アクセストークンの取得

↓以下の記事を参照 http://qiita.com/_RJ/items/186f5e9c6d7610a39d01 認証コードの取得のscopeには、

https://www.googleapis.com/auth/drive%20https://www.googleapis.com/auth/drive.readonly%20https://www.googleapis.com/auth/presentations%20https://www.googleapis.com/auth/presentations.readonly

を使用する。

2. スライドの取得

  1. アクセストークンの入力
  2. presentationIdの入力
    (https://s.google.com/presentation/d/{presentationId}/edit#slide=id.p)
  3. 以下のコマンドを打つ
curl \ 
-i -H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Content-Length: 0" \
-H "Authorization: Bearer {アクセストークン}" \
-X GET "https://slides.googleapis.com/v1/presentations/{presentationId}"

3. ページの取得

  1. アクセストークンの入力
  2. presentationIdの入力
    (https://s.google.com/presentation/d/{presentationId}/edit#slide=id.p)
  3. presentationIdの入力
    (https://docs.google.com/presentation/d/{presentationId}/edit#slide=id.{pageId})
  4. 以下のコマンドを打つ
curl \
-i -H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Content-Length: 0" \
-H "Authorization: Bearer {アクセストークン}" \
-X GET "https://slides.googleapis.com/v1/presentations/{presentationId}/pages/{pageObjectId}"

とりあえずGoogle API Acccess Tokenを取得する

googleapi curl

1. client_id、client_secretの取得

  1. https://console.developers.google.com/flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE&reusekey=true&hl=ja にアクセス
  2. プロジェクトの作成
  3. 認証情報を作成
  4. クライアントIDの作成
  5. 承認済みのリダイレクトURIhttps://www.google.co.jp/ を入力
  6. 作成
  7. client_idとclient_secretをメモ

2. 認証コードの取得

  1. client_idの入力
  2. scope(使用する機能)が複数ある場合は%20区切りで入力
    例: https://www.googleapis.com/auth/drive%20https://www.googleapis.com/auth/drive.readonly
    一覧:https://developers.google.com/identity/protocols/googlescopes
  3. ブラウザでアクセスする
https://accounts.google.com/o/oauth2/v2/auth?response_type=code
&client_id={client_id}
&redirect_uri=https://www.google.co.jp/
&scope={scope}
&access_type=offline

以下のようなURLにリダイレクトされるので認証コードをメモ

https://www.google.co.jp/?code={認証コード}#

3. access_tokenの取得

  1. 承認コードの入力
  2. client_idの入力
  3. client_secretの入力
curl \
--data "code={承認コード}" \
--data "client_id={client_id}" \
--data "client_secret={client_secret}" \
--data "grant_type=authorization_code" \
--data "access_type=offline" \
https://www.googleapis.com/oauth2/v4/token

以下のjsonからアクセストークンを取得できる

{
 "access_token": "{アクセストークン}",
 "token_type": "Bearer",
 "expires_in": 3600,
 "refresh_token": "**"
}