Google drive api Files: get doesn't list full metadata - google-drive-api

I tried using the example get method on the google drive api documentation, however what is returned is not the full metadata of the file, only this:
"kind": "drive#file",
"id": "1vbLiXALYOYoVev1KD_ajVBfh5_CgvGgP",
"name": "3.png",
"mimeType": "image/png",
"result": {
"kind": "drive#file",
"id": "1vbLiXALYOYoVev1KD_ajVBfh5_CgvGgP",
"name": "3.png",
"mimeType": "image/png"
}
}
What should appear is something with many more fields:
{
"kind": "drive#file",
"id": "1vbLiXALYOYoVev1KD_ajVBfh5_CgvGgP",
"etag": "\"MTU4Njg3NTU3MjUxOQ\"",
"selfLink": "",
"webContentLink": "",
"alternateLink": "",
"embedLink": "",
"iconLink": "",
"thumbnailLink": "",
"title": "3.png"
// ... and so on
I get the full response when I use the "try api" screen on the api docs, but not when calling it from javascript:
function printFile(fileId) {
appendPre(fileId)
var request = gapi.client.drive.files.get({
'fileId': fileId
});
request.execute(function(resp) {
console.log(JSON.stringify(resp, null, 2))
});
}
I used the https://www.googleapis.com/auth/drive.file scope, which is listed as a scope sufficient for the request to be completed. Help!

How about this modification?
At Drive API V3, when fields property is not used, a part of fields is returned. So in your case, for example, you can retrieve other parameters using fields: "*". When your script is modified, please modify as follows.
From:
var request = gapi.client.drive.files.get({
'fileId': fileId
});
To:
var request = gapi.client.drive.files.get({
'fileId': fileId,
'fields': "*" // Added
});
Reference:
Parameters of Files: get

Related

Building Webhook to send Recordings info from Zoom to Google App Script - Getting Status 302

I'm building a webhook that will send the completed recordings info from Zoom to a deployed Web App. Webhook will fire when the recording is completed.
Below is the complet schema of the event notification:
{
"event": "string",
"payload": {
"account_id": "string",
"object": {
"id": "integer",
"uuid": "string",
"host_id": "string",
"topic": "string",
"type": "integer",
"start_time": "string",
"timezone": "string",
"host_email": "string",
"duration": "integer",
"share_url": "string",
"total_size": "integer",
"recording_count": "integer",
"recording_files": [
{
"id": "string",
"meeting_id": "string",
"recording_start": "string",
"recording_end": "string",
"file_type": "string",
"file_size": "number",
"play_url": "string",
"download_url": "string",
"status": "string",
"recording_type": "string"
}
]
}
}
}
This is my Web App code:
function doGet(e) {
return ContentService.createTextOutput('doGet request');
}
function doPost(e) {
try {
var input = JSON.stringify(e.postData.contents);
input = JSON.parse(input);
//var myData = JSON.parse(e.postData.contents);
//return HtmlService.createHtmlOutput(myData);
}
catch (e) {
throw new Error(e);
}
return ContentService.createTextOutput("doPost received");
}
The Web App is deployed with Execute the app as the owner and everyone has access to the app.
I'm getting Status 302 on Zoom side.
Please give me some advice on this. Thank you in advance!
How about this modification?
Modification points:
At Web Apps, when ContentService.createTextOutput is returned, it seems that the redirect might be used. From the status code of 302 in your question, I thought that this might be the reason of your issue. So for example, in order to avoid this issue, how about the following modification?
Modified script:
function doPost(e) {
try {
var input = JSON.stringify(e.postData.contents);
input = JSON.parse(input);
//var myData = JSON.parse(e.postData.contents);
//return HtmlService.createHtmlOutput(myData);
}
catch (e) {
throw new Error(e);
}
// return ContentService.createTextOutput("doPost received"); // Removed
}
When you modified the script of Web Apps, please redeploy Web Apps as new version. By this, the latest script is reflected to Web Apps. Please be careful this.
Note:
If the status code was changed to 200 when no values are returned to the zoom side, in this case, I think that HtmlService.createHtmlOutput might be able to be also used.

How to find selected format file using google drive api

I was following the refference from google drive api v3 and trying to find the file name with format is .capx
here the api https://www.googleapis.com/drive/v3/files?q='FOLDER_ID'+in+parents&name='.capx'&pageSize=1000&fields=files(name,size,description,webContentLink,webViewLink,createdTime)&key=
output
{
"files": [
{
"name": "tes.zip",
"webContentLink": "",
"webViewLink": "",
"createdTime": "",
"size": ""
},
{
"name": "tes.capx",
"webContentLink": "",
"webViewLink": "",
"createdTime": "",
"size": ""
}
]
}
I want output like this
{
"files": [
{
"name": "tes.capx",
"webContentLink": "",
"webViewLink": "",
"createdTime": "",
"size": ""
}
]
}
You want to retrieve the files which has the extension of .capx using the search query of the method of files.list in Drive API.
If my understanding is correct, how about this answer? In this answer, 'FOLDER_ID' in parents and name contains '.capx' is used as the search query.
Modified endpoint:
https://www.googleapis.com/drive/v3/files?pageSize=1000&q='FOLDER_ID' in parents and name contains '.capx'&fields=files(name,size,description,webContentLink,webViewLink,createdTime)
or
https://www.googleapis.com/drive/v3/files?pageSize=1000&q=%27FOLDER_ID%27%20in%20parents%20and%20name%20contains%20%27.capx%27&fields=files(name%2Csize%2Cdescription%2CwebContentLink%2CwebViewLink%2CcreatedTime)
References:
Files: list
Search for files and folders
If I misunderstood your question and this was not the result you want, I apologize.

How to deploy Google Sheet as Web-app using Google API

I have a little proble with Google Sheets API
I have a Google Sheet Document on my GDrive. And I can work with it using Google Sheets API and Google Drive API. So I can move it, update it or make copies.
My task is:
1. make a copy of this document (I can do this)
2. publish this copy as web app. So each copy has a doGet() functon inside so it can be published as a Web app. Manually it can be done like: Publish -> Deploy as web app.. But I can't find any API to do this.
Get an URL of published service
UPDATE
I read documentation projects.deployments.create And I maanged to create a new deployment (before that I should create a version) But my new deployemnt has no web access, no url etc. IF I check via projects.deployments.list it shows:
{
"deploymentId": "AKfycbxVfuoeIQmumgy_Efhw12NCcqE7vqosYoxbDiKj5CT4mL_GbtybXsh1ppMIX22wQX20",
"deploymentConfig": {
"scriptId": "1zfjbALVe0jGbZCtqjFR0RP2-O___hR7MtAlx3biuJGXKsrKh3y1W0hMT",
"versionNumber": 1,
"manifestFileName": "appsscript",
"description": "v1"
},
"updateTime": "2019-05-13T22:33:23.760Z"
}
And if I will do this manually via web interface it will looks like
{
"deploymentId": "AKfycbyn3smPKxJcZwsm9SzSTtzNCAcWJzf1OVs4WTslvHo",
"deploymentConfig": {
"scriptId": "1zfjbALVe0jGbZCtqjFR0RP2-O___hR7MtAlx3biuJGXKsrKh3y1W0hMT",
"manifestFileName": "appsscript"
},
"updateTime": "1970-01-01T00:00:00Z",
"entryPoints": [
{
"entryPointType": "WEB_APP",
"webApp": {
"url": "https://script.google.com/macros/s/AKfycbyn3smPKxJcZwsm9SzSTtzNCAcWJzf1OVs4WTslvHo/exec",
"entryPointConfig": {
"access": "ANYONE_ANONYMOUS",
"executeAs": "USER_DEPLOYING"
}
}
}
]
}
The Apps Script API needs to be used. You can use the REST API and make a UrlFetchApp.fetch(url) request. This is a two step process. First you must create a new Apps Script file, then you must update that new Apps Script file with new contents in the manifest file. The manifest file must have a property for webapp which is what designates the type of deployment.
The code will probably look something like the following:
function deployA_project() {
var id, OAuthToken,options,payload,rtrn,url;
id = ScriptApp.getScriptId();//Get the project ID of this script project
Logger.log('id: ' + id)
url = 'https://script.googleapis.com/v1/projects/' + id + '/deployments';//For REST
OAuthToken = ScriptApp.getOAuthToken();
payload = {
"versionNumber": number,
"manifestFileName": string,
"description": string
}
options = {
"method" : "POST",
"muteHttpExceptions": true,
"headers": {
'Authorization': 'Bearer ' + OAuthToken
},
"contentType": "application/json",
"payload": JSON.stringify(payload)
};
rtrn = UrlFetchApp.fetch(url,options);
Logger.log('rtrn: ' + rtrn)
}
See the documentation:
projects.deployments.create
How the apps script project is deployed is designated in the manifest file:
{
"timeZone": "America/New_York",
"dependencies": {
},
"webapp": {
"access": "MYSELF",
"executeAs": "USER_DEPLOYING"
},
"exceptionLogging": "STACKDRIVER"
}
The API doesn't provide a configuration setting for creating the type of deployment. So, turning the deployment into a Web App is done by updating the manifest file. This must be a two step process. First, you create the new project file, then you update it with a JSON object of file content. You can designate the file content of the manifest file named "appsscript.json"
The content must be JSON in the following format:
{
"scriptId": "scriptId",
"files": [{
"name": "appsscript",
"type": "JSON",
"source": "{\"timeZone\":\"America/New_York\", \"webapp\": {\"access\": \"MYSELF\",\"executeAs\": \"USER_DEPLOYING\"},\"exceptionLogging\":\"STACKDRIVER\"}",
"lastModifyUser": {
"name": "MyName",
"email": "example#gmail.com",
}
}]
}
You need to make another request to a different url, and the request must be a PUT request in order to make an update:
url = 'https://script.googleapis.com/v1/projects/' + id + '/deployments/' + {deploymentId}
var newContent = {
"scriptId": "scriptId",
"files": [{
"name": "appsscript",
"type": "JSON",
"source": "{\"timeZone\":\"America/New_York\", \"webapp\": {\"access\": \"MYSELF\",\"executeAs\": \"USER_DEPLOYING\"},\"exceptionLogging\":\"STACKDRIVER\"}",
"lastModifyUser": {
"name": "MyName",
"email": "example#gmail.com",
}
}]
}
var requestBody = {};
requestBody.files = newContent;
requestBody.deploymentConfig = {
"scriptId": string,
"versionNumber": number,
"manifestFileName": string,
"description": string
}
options = {
"method" : "PUT",
"muteHttpExceptions": true,
"headers": {
'Authorization': 'Bearer ' + OAuthToken
},
"contentType": "application/json",
"payload": JSON.stringify(requestBody)
};
rtrn = UrlFetchApp.fetch(url,options);
Logger.log('rtrn: ' + rtrn)

Revisions list and get missing information

Using the Google APIs Explorer as well as the official C# library for Google Drive API v3, the response is missing most of the documented fields. I specifically need access to who did the revisions, which should be accessible via $.lastModifyingUser.
I've tried this on my domain admin account as well as a service account, so it shouldn't be a permission issue, at least not that I can see. What am I doing wrong, if anything?
List:
{
"kind": "drive#revisionList",
"revisions": [
{
"kind": "drive#revision",
"id": "1",
"mimeType": "application/vnd.google-apps.spreadsheet",
"modifiedTime": "2016-11-16T18:29:29.527Z"
},
{
"kind": "drive#revision",
"id": "14",
"mimeType": "application/vnd.google-apps.spreadsheet",
"modifiedTime": "2016-11-16T18:35:49.184Z"
},
...
Single get:
{
"kind": "drive#revision",
"id": "134088",
"mimeType": "application/vnd.google-apps.spreadsheet",
"modifiedTime": "2017-05-24T11:48:00.788Z"
}
You need to add fields="*", or fields="permissions(id,lastModifyingUser)" to your request to instruct Drive to return the full resource. By default, only a minimal set of properties is returned.
I was not able to retrieve the "lastModifyingUser" from the revisions API but I was able to retrieve the "lastModifyingUser" from the Files.get fro example:
File foundFile = service.files().get(id)
.setSupportsTeamDrives(true)
.setFields("parents, webViewLink, properties, lastModifyingUser")
.execute();
System.out.println("Found file is " + foundFile);
System.out.println("Parents " + foundFile.getParents());
System.out.println("Owners " + foundFile.getOwners());
System.out.println("Props " + foundFile.getProperties());
System.out.println("Last user " + foundFile.getLastModifyingUser());

gmail api returning emails outside of query parameters

Building a Chrome Extension for Gmail, trying to retrieve only emails addressed to me. I use the gapi thread API Explorer at the bottom of this page to test. It returns the inbox-only items as expected as you can see at the bottom of the image below. I copy and paste the request URL https://www.googleapis.com/gmail/v1/users/me/threads?=to%3Adan%40pledgmail.com+in%3Ainbox&access_token= + thisToken
from the API Explorer above into my background.js code below, but I am returned emails that I have sent in addition to those I have received.
Note: I do change the "key" in the request URL from the API Explorer to "access_token", else no request I make works.
(In case my code doesn't give it away, I'm a newbie. Any help is sincerely appreciated, and I am grateful for your time.)
Google API Explorer results (expected)
My code from background.js with copied request URL
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
thisToken = token
chrome.runtime.onMessage.addListener(
function(request,sender,sendResponse){
var gapiRequestAllThreadsToSelf = "https://www.googleapis.com/gmail/v1/users/me/threads?=to%3Adan%40pledgmail.com+in%3Ainbox&access_token=" + thisToken
var getAllThreadsToSelf = function (gapiRequestURL)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", gapiRequestURL, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
var threadsToSelf = getAllThreadsToSelf(gapiRequestAllThreadsToSelf)
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {data: threadsToSelf}, function(response) {
});
});
}
);
});
}
})
Return with unexpected 9 emails instead of 6 (top 3 are emails I sent)
{
"threads": [
{
"id": "14e69c9075bd53",
"snippet": "Thank you!",
"historyId": "8573"
},
{
"id": "14e69be815c6a0",
"snippet": "Thaaaanks",
"historyId": "8550"
},
{
"id": "14e644211d19b0",
"snippet": "Reply to this email, Danny boy",
"historyId": "8481"
},
{
"id": "14e1c4702de573",
"snippet": "Hey guys, Here is the gmail Chrome extension I am working on. This is the basic mvp I'm iterating",
"historyId": "8328"
},
{
"id": "14e13259f00f0e",
"snippet": "Hello Daniel Klos, Thanks for buying from Chrome Web Store using Google Wallet! Chrome Web Store will",
"historyId": "8431"
},
{
"id": "14e12da5ca9c16",
"snippet": "Here are your account details. Sign in ยป Your billing setup is complete. See your account details",
"historyId": "6181"
},
{
"id": "14e12d1e3e41ba",
"snippet": "Hi Dan Welcome to your Gmail inbox Save everything With up to 30GB of space, you'll never need to",
"historyId": "2678"
},
{
"id": "14e12d1e1be7b3",
"snippet": "Hi Dan Get the official Gmail app The best features of Gmail are only available on your phone and",
"historyId": "6114"
},
{
"id": "14e12d1e19e865",
"snippet": "Hi Dan Work smarter with Gmail and Google Apps Manage Calendar meetings Google Calendar makes",
"historyId": "2682"
}
],
"resultSizeEstimate": 9
}
My manifest.json for good measure
{
"manifest_version": 2,
"key": "redacted",
"name": "redacted",
"description": "Description",
"version": "0.0.2.0",
"default locale": "en",
"icons": { "128": "imgs/pledge_pin.png"},
"content_scripts" : [
{
"matches": ["*://mail.google.com/mail/*"],
"js": ["js/jquery.js", "js/compose.js", "bower_components/jqnotifybar/jquery.notifyBar.js"],
"css": ["css/stylesheet.css", "bower_components/jqnotifybar/css/jquery.notifyBar.css"]
}
],
"background": {
"scripts": ["scripts/background.js"]
},
"permissions": [
"identity"
],
"oauth2": {
"client_id": "redacted",
"scopes": ["https://www.googleapis.com/auth/gmail.modify"]
}
}
Doing threads.list() will return threads where any message in the thread matches the criteria. If you only want messages that match a specific criteria then do messages.list() instead.
There is a typo in your code which makes your code act differently than API Explorer. You are missing 'q' in the query string which makes the result includes all emails without filter.
var gapiRequestAllThreadsToSelf = "https://www.googleapis.com/gmail/v1/users/me/threads?q=to%3Adan%40pledgmail.com+in%3Ainbox&access_token=" + thisToken
Try this out to get rid of the nuisance.