Reputation: 1
I am trying to update all my google drive images description. I have access to google drive and I am able to get results with
gapi.client.drive.files.list({ 'pageSize': 1000, 'fields':'files,nextPageToken', 'q':query, 'orderBy':'name', 'access_token':accesToken });
After that I want to update all files description but I got the result that I need to login. I am using OAuth 2.0 Playground with permission to all my drive.
gapi.client.drive.files.update({ 'fileId': fileid, 'access_token':accesToken, 'resource': body });
Any idea how to login or what I am not doing right?
Upvotes: 0
Views: 418
Reputation: 2998
Try to double check if you follow properly the steps here to Authorize your requests with OAuth, also make sure that you use the correct scope in your application. Here is the link that will explain you the meaning and purpose of each scope.
Now to update your file, this documentation can help you with that. The v2 version of this documentation has an example of Javascript code that updates the file.
/**
* Update an existing file's metadata and content.
*
* @param {String} fileId ID of the file to update.
* @param {Object} fileMetadata existing Drive file's metadata.
* @param {File} fileData File object to read data from.
* @param {Function} callback Callback function to call when the request is complete.
*/
function updateFile(fileId, fileMetadata, fileData, callback) {
const boundary = '-------314159265358979323846';
const delimiter = "\r\n--" + boundary + "\r\n";
const close_delim = "\r\n--" + boundary + "--";
var reader = new FileReader();
reader.readAsBinaryString(fileData);
reader.onload = function(e) {
var contentType = fileData.type || 'application/octet-stream';
// Updating the metadata is optional and you can instead use the value from drive.files.get.
var base64Data = btoa(reader.result);
var multipartRequestBody =
delimiter +
'Content-Type: application/json\r\n\r\n' +
JSON.stringify(fileMetadata) +
delimiter +
'Content-Type: ' + contentType + '\r\n' +
'Content-Transfer-Encoding: base64\r\n' +
'\r\n' +
base64Data +
close_delim;
var request = gapi.client.request({
'path': '/upload/drive/v2/files/' + fileId,
'method': 'PUT',
'params': {'uploadType': 'multipart', 'alt': 'json'},
'headers': {
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
},
'body': multipartRequestBody});
if (!callback) {
callback = function(file) {
console.log(file)
};
}
request.execute(callback);
}
}
For the sample javascript code in v3, check this link.
Upvotes: 0