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
Rodolfo NoviskiRodolfo Noviski 

Salesforce Integration with Google Drive

Hello , I 'm trying to accomplish the following request:

    request.setHeader('Authorization', 'Bearer {Token}');
            String scope =  ','+
        request.setHeader('Scope', scope);
        String body = '{\'value\':\'drive.permissions.insert\',\'type\':\'anyone\',\'role\':\'writer\'}';
        System.debug('Set Endpoint');
        System.debug('Set Method');

But I do not know how to automatically get the token that is sought. Could anyone help me?

thank you
Sfdc CloudSfdc Cloud
Hi Rodolfo,
                  You need to have App key,App Secret and redirect Uri for sending the request to google drive from your salesforce org.After authorization will get successful you will get access token
//Fetched from URL  
    private String code ;  
    //App key of your App
    private string key = '' ;  
    //App Secret of your App
    private string secret = 'zjr1679QYeFAw_SnqjRBSH1q' ;  
   //Url where u need to have acccess token
    private string redirect_uri = '' ;  
    public GoogleDriveController()  
        code = ApexPages.currentPage().getParameters().get('code') ;  
        //Get the access token once we have code  
        if(code != '' && code != null)  
            AccessToken() ;  
    public PageReference DriveAuth()  
        PageReference pg = new PageReference(GoogleDriveAuthUri (key , redirect_uri)) ;  
        return pg ;  
    public String GoogleDriveAuthUri(String Clientkey,String redirect_uri)  
        String key = EncodingUtil.urlEncode(Clientkey,'UTF-8');  
        String uri = EncodingUtil.urlEncode(redirect_uri,'UTF-8');  
        String authuri = '';  
        authuri = ''+  
        return authuri;  
    public void AccessToken()  
        //Getting access token from google  
        HttpRequest req = new HttpRequest();  
        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()));  
        Http h = new Http();  
        String resp;  
        HttpResponse res = h.send(req);  
        resp = res.getBody();  
        System.debug(' You can parse the response to get the access token ::: ' + resp);  
If this helps you out mark it as best ans to help other !!!