function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gabriel E CasarsaGabriel E Casarsa 

Automate Google Drive Integration

Hello everyone.
I have a requirement that asks me to backup the documents in Salesforce in Google Drive.
I have already managed to connect and load the documents, but I need to automate this process, logging into Google automatically without the screen in which I request the credentials.
I do not have much experience in web services, so I do not know if I'm doing the order right to the server.
HttpRequest req = new HttpRequest();
            req.setMethod('POST');
            req.setEndpoint('https://accounts.google.com/o/oauth2/token');
            req.setHeader('content-type', 'application/x-www-form-urlencoded');
            String messageBody = 'code='+code+'&client_id='+key+'&client_secret='+secret+'&redirect_uri='+redirect_uri+'&grant_type=authorization_code';
            
            req.setHeader('Content-length', String.valueOf(messageBody.length()));
            req.setBody(messageBody);
            req.setTimeout(60*1000);
            Http h = new Http();
            String resp;
            HttpResponse res = h.send(req);
            resp = res.getBody();

Is there a way to pass the email and password in the body of the request to log in?

Greetings thank you!