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
shailesh.gusain.sfd1.3960741070027976E12shailesh.gusain.sfd1.3960741070027976E12 

getting access token of google adwords

following code i am using to get acces token from GOOGLE ADWORDS it showing -error 400 with
  grant_type:invalid
  code:invalid
  though my auth code is correct:
  can anybody tell me what am i missing here?
 
       public void AccessToken() 
                            { 
        //Getting access token from google
        redirect_uri = encodingutil.urlEncode(redirect_uri, 'UTF-8');
        code = encodingutil.urlEncode(code , 'UTF-8');
        secret  = encodingutil.urlEncode(secret , 'UTF-8');
        key = encodingutil.urlEncode(key, 'UTF-8');
      
        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(); 
         
        System.debug(' You can parse the response to get the access token ::: ' + resp); 
       }
    }
shailesh.gusain.sfd1.3960741070027976E12shailesh.gusain.sfd1.3960741070027976E12
is rest service  applicable for google adwords?