0

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 1 Link 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.

pranav
  • 25
  • 5

1 Answers1

2

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());
}
Darshana
  • 71
  • 8