Last active
January 28, 2018 09:50
-
-
Save tanaikech/78058814cdcbb80207b87e116347a997 to your computer and use it in GitHub Desktop.
Google Apps Scriptを使用したGoogle Drive上のファイル移動 ref: http://qiita.com/tanaike/items/1d3b2cac43cf5c34e9f7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sourcefile = [コピー元ファイル名]; // file name | |
var destfolder = [コピー先フォルダ名]; // folder name | |
var destfolder = DriveApp.getFoldersByName(destfolder).next(); | |
var file = DriveApp.getFilesByName(sourcefile).next(); | |
var sourcefolder = file.getParents().next(); | |
destfolder.addFile(file); | |
sourcefolder.removeFile(file); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sourcefile = DriveApp.getFilesByName([コピー元ファイル名]).next().getId(); // file name | |
var destfolder = DriveApp.getFoldersByName([コピー先フォルダ名]).next().getId(); // folder name | |
var accesstoken = [アクセストークン]; | |
UrlFetchApp.fetch('https://www.googleapis.com/drive/v2/files/' + sourcefile, { | |
method:'put', | |
headers: { | |
'Authorization': 'Bearer ' + accesstoken, | |
'uploadType' : 'multipart/related' | |
}, | |
contentType: 'application/json', | |
payload: JSON.stringify({'parents': [{id: destfolder}]}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Drive.Files.update( | |
{"parents": [{"id": "## Folder ID ##"}]}, | |
"## File ID ##" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X PUT -H 'Content-Type: application/json' -H 'uploadType: multipart/related' -H 'Authorization: Bearer [アクセストークン]' https://www.googleapis.com/drive/v2/files/[コピー元ファイルID] -d '{"parents": [{"id": "[コピー先フォルダID]"}]}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -H 'Content-Type: application/json' -H 'Authorization: Bearer [アクセストークン]' https://www.googleapis.com/drive/v2/files -o list.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ jq -r ".items[].title" list.json | |
ファイル名 | |
$ jq -r ".items[].id" list.json | |
ファイルID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"error": { | |
"errors": [ | |
{ | |
"domain": "global", | |
"reason": "insufficientPermissions", | |
"message": "Insufficient Permission" | |
} | |
], | |
"code": 403, | |
"message": "Insufficient Permission" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment