How To Create A New Folder In Google Drive By Using Trigger On Custom Object Creation?
Created trigger on custom object. And to create folder will call @future method to support rest API calls. But I am not getting the proper code or guidelines to follow for folder creation in google drive.
Found below links for folder creation but I am not getting it Link 1Link 2
Also I have the integration of my org and my drive because for one of my visualforce page I want to show drive picker for file selection and it is working correctly. But for folder creation I am not getting how to call methods one by one? For example to authenticate and then create folder.
Please help us and let me know if you want any other details.
Answer
You can call @future method from trigger and can call create folder method by using access token and correct parameters. You can refer below code for folder creation.
public static void createFolder(String folderName, String accessToken) {
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('https://www.googleapis.com/drive/v3/files');
req.setHeader('Authorization', 'Bearer '+accessToken);
req.setHeader('content-type', 'application/json');
String body = '{"name" : "'+ folderName +'","mimeType" : "application/vnd.google-apps.folder"}';
req.setTimeout(60*1000);
req.setBody(body);
Http http = new Http();
HttpResponse res = http.send(req);
System.debug('===== Response==='+ res.getBody());
}
Related Questions
- → Google API - request for token from Oauth2 returns null token
- → PHP: Uploading public files to a folder inside a Google storage bucket
- → Get way Points between two locations
- → Illegal state exception while calling signout through GoogleApiClient
- → GoogleApiClient.connect() causes crash
- → Google Sheets API v4 for Flutter/Dart
- → How to change the position or remove the default GPS icon of google maps?
- → personFields mask is required. Please specify one or more valid paths
- → Cloud Tasks is not available in the "specified" region
- → Node js Google drive api error
- → Google translation API for a Chrome extension
- → Specify source language Google Translation API in Python
- → Flutter Google Calendar Api list Events