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
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>
SubratSubrat (Salesforce Developers) 
Hello ,

Based on the provided code, it seems like you are trying to integrate with Gmail using OAuth2.0. The "GmailIntegrationController" class is responsible for handling the OAuth2.0 authentication process and making API calls to Gmail.

In your code, the gmailContent() method is expected to return the content that you want to send via the Gmail API. Currently, the gmailContent() method is returning a sample message body with static data. If you want to send dynamic data, you need to modify this method to create the message body based on your specific requirements.

For example, if you want to send data from the Account object, you could modify the gmailContent() method to retrieve data from Account records and create a dynamic message body. Here's a sample modification to demonstrate how you could achieve this:
private String gmailContent() {
    String messageBodies = 'Number ,PTC,Last,First,Mid,Gender,Nationality,DOB,Passport No,Email,Phone\r';
    
    // Retrieve data from Account records and create message body
    List<Account> accounts = [SELECT Number_c, PTCc, LastName, FirstName, MiddleName, Genderc, Nationalityc, DOBc, Passport_No_c, Email, Phone FROM Account];
    for (Account acc : accounts) {
        messageBodies += acc.Number_c + ',' + acc.PTC_c + ',' + acc.LastName + ',' + acc.FirstName + ',' + acc.MiddleName + ','
            + acc.Gender_c + ',' + acc.Nationalityc + ',' + String.valueOf(acc.DOBc) + ',' + acc.Passport_No_c + ','
            + acc.Email + ',' + acc.Phone + '\r';
    }
    return messageBodies;
}
In this modified gmailContent() method, we are querying data from the Account object and appending it to the message body in CSV format. You can customize this method to include any other fields or data from other objects that you need to send via the Gmail API.

Please note that this is just a sample modification to demonstrate how to dynamically populate the message body. Depending on your specific use case and data requirements, you may need to adjust the query and formatting of the message body accordingly.