LoginSignup
0
0

More than 5 years have passed since last update.

Google APIで特定のファイルを出力する

Last updated at Posted at 2017-09-04

ログインの権限で、ドライブを触れるようにする。

https://accounts.google.com/o/oauth2/auth?client_id=[client_id]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/drive&response_type=code&approval_prompt=force&access_type=offline

アクセストークンを取得する。

curl -k -d client_id=[client_id] -d client_secret=[client_secret] -d redirect_uri=urn:ietf:wg:oauth:2.0:oob -d grant_type=authorization_code -d code=[ブラウザで取得したコード] https://accounts.google.com/o/oauth2/token

ファイルのリビジョン情報を取得する。

curl -sSLG \
    -H 'Authorization: Bearer [access_token]’ \
    'https://www.googleapis.com/drive/v3/files/[file_id]/revisions?fields=revisions(id%2CmodifiedTime)'

※もし、reasonがaccessNotConfiguredとなった場合、Drive APIが向こうになっているので有効にする。
https://console.developers.google.com/apis/api/drive.googleapis.com/overview?project=[プロジェクトID]

出力形式を指定してファイルを出力する。

curl -sSLG \
    -d "mimeType=application/zip" \
    -H 'Authorization: Bearer [access_token]' \
    "https://www.googleapis.com/drive/v3/files/[file_id]/export?revisions=[revision番号]“\
    -o [出力するファイル名]

他のmimeTypeは、下記URLに記述してある。
https://developers.google.com/drive/v3/web/manage-downloads


APIを利用するには下記設定が必要。
OAuth2の設定をする。
https://console.developers.google.com/apis/credentials

google api+を有効にする

https://console.developers.google.com/apis/api/plus/overview

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