I am using the following code to get acces token from Google Adwords but it is showing error 400
with
grant_type:invalid code:invalid
Though my auth code should be 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(' jsonresponse ' + resp);
}
}
Is this rest service is applicable for Google adwords?