• Sheeba Narayanan 7
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
Im using below code to get access token from Google Drive and getting error says 'Invalid grant'. Here im passing code as Auth. Provider ID. Can anyone please assist on this?
try{
//Getting access token from google
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('Response :::' + resp);
JSONParser parser = JSON.createParser(resp);
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)) {
String fieldName = parser.getText();
parser.nextToken();
if (fieldName == 'access_token') {
accesstoken = parser.getText();
} else if (fieldName == 'expires_in') {
expiresIn = parser.getIntegerValue();
} else if (fieldname == 'token_type') {
tokentype = parser.getText();
}

} }
} catch
(Exception e) {
System.debug(LoggingLevel.ERROR,'Call exception ' + e.getMessage());
}
System.debug('access token ::::' + accesstoken);



How to write testmethod for getDetails() here.
public class addressDetails{

        public String latitude {get;set;}
        public String longitude {get;set;}
        ........
    }
     public addressDetails getDetails(String strAddress)
     {
             Http http = new Http();
            HttpRequest request = new HttpRequest();
         IF (strAddress!=null){
             strAddress=strAddress.replaceAll(' ', '+');
                    addressDetails addr=new addressDetails();
        if (latitude!='') { addr.latitude=latitude;}
        if (longitude!=''){ addr.longitude=longitude;}
        ........................
        System.debug('Value of adddress is here : ' +addr);
        
        return addr;
     }
how to hide standard stylesheets in lightning component?
Im using below code to get access token from Google Drive and getting error says 'Invalid grant'. Here im passing code as Auth. Provider ID. Can anyone please assist on this?
try{
//Getting access token from google
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('Response :::' + resp);
JSONParser parser = JSON.createParser(resp);
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)) {
String fieldName = parser.getText();
parser.nextToken();
if (fieldName == 'access_token') {
accesstoken = parser.getText();
} else if (fieldName == 'expires_in') {
expiresIn = parser.getIntegerValue();
} else if (fieldname == 'token_type') {
tokentype = parser.getText();
}

} }
} catch
(Exception e) {
System.debug(LoggingLevel.ERROR,'Call exception ' + e.getMessage());
}
System.debug('access token ::::' + accesstoken);



How to write testmethod for getDetails() here.
public class addressDetails{

        public String latitude {get;set;}
        public String longitude {get;set;}
        ........
    }
     public addressDetails getDetails(String strAddress)
     {
             Http http = new Http();
            HttpRequest request = new HttpRequest();
         IF (strAddress!=null){
             strAddress=strAddress.replaceAll(' ', '+');
                    addressDetails addr=new addressDetails();
        if (latitude!='') { addr.latitude=latitude;}
        if (longitude!=''){ addr.longitude=longitude;}
        ........................
        System.debug('Value of adddress is here : ' +addr);
        
        return addr;
     }