+ Start a Discussion
Ashmi PatelAshmi Patel 

Required parameter is missing: response_type

This is the class code...for gmail integration
And what should be gmailContent in this code???

public with sharing class GmailIntegrationController{
    public List<AccountWrapper> accountswrappers { get; set; }
    String code;
    String key;
    String secret;
    String redirect_uri;
    String CheckFlag;

public GmailIntegrationController(ApexPages.StandardController controller){
        init();
}
    public void init()
    {
        code=null;
        key = '';
        secret = '';
        redirect_uri = 'https://gmail.google.com';
        System.debug('shhdhshdhshdhshdhhd' + ApexPages.currentPage().getUrl());
        code = ApexPages.currentPage().getParameters().get('code');
        System.debug('dsdsjdsjdjsjdjsjdsjd' + code);
       accountswrappers = new List<AccountWrapper>();
            if(code != '' && code != null){
                authenticationAndUpload();
                    return;
            }
}
    public void authenticationAndUpload(){
        System.debug('codesdd:::' + code);
            if(code != '' && code != null)
            {
                System.debug('codesdd:::' + code);
                AccessToken();
            }
            }

public void AccessToken(){
    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';
 System.debug('messageBody::::' + messageBody );
        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(' This is the reponse from google: ' + resp );
        String str = resp;
        List<String> lstStr = str.split(',');
        System.debug('@@@'+lstStr[0]);
        List<String> lstStr1 = lstStr[0].split(':');
        System.debug('###'+lstStr1[1]);
        String st = lstStr1[1].remove('"').trim();
        System.debug('@#@'+st);
        
        System.debug('JHSDHSDJSJDJSD'  + st + 'TETTETTETTE');
Http http = new Http();
        req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint('https://accounts.google.com/o/oauth2/token');
        req.setHeader('content-type', 'text/csv');
        req.setHeader('Authorization','Bearer '+st);
        String contentGmail = gmailContent();
        req.setBody(contentGmail);  
        req.setTimeout(60*1000);
        HttpResponse respp = http.send(req);
}
public PageReference GmailAuth()
    {
        PageReference pg = new PageReference(GmailAuthUri (key , redirect_uri)) ;
        return pg;
    }
    
    public String GmailAuthUri(String Clientkey,String redirect_uri)
    {
        String key = EncodingUtil.urlEncode(Clientkey,'UTF-8');
        String uri = EncodingUtil.urlEncode(redirect_uri,'UTF-8');
        String authuri = '';
        authuri = 'https://accounts.google.com/o/oauth2/v2/auth?'+
        'scope = https://gmail.google.com/' +
        'state=security_token%ObUT6axTPjcyVZRAb3e8MXtl71%26url%3Dhttps://oa2cb.example.com/myHome&'+
        'redirect_uri=' +uri+
        '&response_type=code&'+
        'client_id='+key+
        '&access_type=offline';
        
        return authuri;
    }
    
    
    private String gmailContent(){
    
        String messageBodies = 'Number ,PTC,Last,First,Mid,Gender,Nationality,DOB,Passport No,Email,Phone\r';
        messageBodies+= 'Hello, Test , test, Test,Test, Test, Test,TEst\r';
        return messageBodies;
    }
 
    public class AccountWrapper{
   
        public Account account{get;set;}
        
        public AccountWrapper(Account account) {
            
            this.account = account;
        }
    }
}

This is apex code ::

<apex:page standardController="Account" extensions="GmailIntegrationController" id="pageId" showHeader="true" sideBar="true">
     <apex:form id="form">
        <apex:pageBlock id="pBd">
        <apex:pageMessages id="msg"/>
         <apex:outPutPanel id="panelId2">     
                <apex:commandButton action="{!GmailAuth}" value="Connect" status="waitMsg"/>
                    </apex:outPutPanel>
                    <apex:outputpanel >
                <apex:actionstatus id="waitMsg">
                    <apex:facet name="start">
                        <div class="waitingSearchDiv" id="el_loading" style="background-color: #fbfbfb; height: 100%; background: rgba(0, 0, 0, 0.5); width: 100%;position:fixed;top:0px;">
                            <div class="waitingHolder" style="height:25px; width:175px; z-index: 100000;margin:0 auto;position:fixed;left:50%;    top:50%;    margin:-75px 0 0 -135px;border-radius: 5px;background:#ECECE3;padding:10px;text-align: center;vertical-align: middle;border: 1px solid #97CAFF;-moz-box-shadow: 3px 3px 4px #000;-webkit-box-shadow: 3px 3px 4px #000;box-shadow: 3px 3px 4px #000;">
                                <img class="waitingImage" src="/img/loading.gif" title="Please Wait..." /> <span class="waitingDescription" style="color:black;">
                                    Please Wait..</span>
                            </div>
                        </div>
                    </apex:facet>
                </apex:actionstatus>
                </apex:outputpanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>