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
anivesh muppaanivesh muppa 

getting error on vf page "Map key etag not found in map"

I have look into the debug==> im getting these values "(etag, selfLink)" And "(etag, selfLink, selfLink)" these values are loading into map i.e FileIdAndNameMapForTheaccount and im placing this map in pageblock table
Hi Everyone,
I got a problem which im enable to understand it .
Im trying to get the files which are in google drive using REST
the response i get is in tthe form of 'Etag' and 'selflink'
i have debug it in which i found "(etag, selfLink)"and for next iteration for loop i get "(etag, selfLink, selfLink)"  and than i load this values into the map (Map<String,String> FileIdAndNameMapForTheaccount)
In vf page :
 <apex:pageBlockTable Value="{!FileIdAndNameMapForTheaccount}" var="file">
                <apex:column headerValue="drive file">
                    <apex:outputLink value="https://www.drive.google.com/open?id={!file}">{!FileIdAndNameMapForTheaccount[file]}</apex:outputLink>
                 </apex:column>
  </apex:pageBlockTable>

Please help me in solving this,

Thanks Inadvance,
Anivesh

Vinod ChoudharyVinod Choudhary
Hi Anivesh ,

Share your Class code, So I can help you.

Thanks
vinod
anivesh muppaanivesh muppa
Vf Page :
<apex:pageBlockTable Value="{!FileIdAndNameMapForTheaccount}" var="file">
                <apex:column headerValue="drive file">
                    <apex:outputLink value="https://www.drive.google.com/open?id={!file}">{!FileIdAndNameMapForTheaccount[file]}</apex:outputLink>
                 </apex:column>
  </apex:pageBlockTable>
Controller:
public class GoogleApiAuthenticationwithsalesforce{
    public String Access_key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    public String Access_Secret='xxxxxxxxxxxxxxxxxxxxxk';   
    public String redirect_uri ='https://formula1-dev-ed--c.ap5.visual.force.com/apex/page';
    private String absyzidentificationtoken;
    Private String access_token;
    public Map<String,String> FileIdAndNameMapForTheaccount{get; set;}
    Private List<string> FileLst;
    private  Integer expiresIn ;
        private String tokentype;
        public string fieldName {get; set;}
public pageReference ListFiles(){
        Google_Drive_Info__c g = new Google_Drive_Info__c();
        g = [SELECT Folder_Id__c FROM Google_Drive_Info__c WHERE Name =:'main'];
       
        String FolderId=g.Folder_Id__c;
        HttpRequest req1 = new HttpRequest();
        req1.setMethod('GET');
        
        req1.setEndpoint('https://www.googleapis.com/drive/v2/files/'+FolderId);
        req1.setHeader('content-type','application/x-www-form-urlencoded');
        req1.setHeader('content-length','0');
        system.debug('Access===============================================>'+access_token);
        req1.setHeader('Authorization','Bearer '+access_token);
        req1.setTimeout(60*1000);
        system.debug('request pattern here is ====='+req1);
        Http h2 = new Http();
        
        HttpResponse res1 = h2.send(req1);
        
        system.debug('=========>check the response query<============='+res1.getBody());
        JSONParser parser1 = JSON.createParser(res1.getBody());
        system.debug('=========>check the parser1<============='+parser1+'and also jsonToken'+JsonToken.FIELD_NAME);
        if(res1.getStatusCode() == 200){
        while (parser1.nextToken() != null)
        {
            if((parser1.getCurrentToken() == JsonToken.FIELD_NAME) && (parser1.getText() == 'id'))
            {
            system.debug('=======================the current token'+parser1.getCurrentToken()+'the next Token is====>'+parser1.nextToken());
                parser1.nextToken();
                FileLst.add(parser1.getText());
                system.debug('===========>files list from the Query'+FileLst);
            }
        }
        Map<String,String> FileIdAndNameMap = FileProperties();
        for(string s : FileLst)
        {
            FileIdAndNameMapForTheaccount.put(s,FileIdAndNameMap.get(s));  
              system.debug('=================>the files in drive  FileIdAndNameMapForTheaccount'+ FileIdAndNameMapForTheaccount.keyset());          
        }
        }
        
    return null;
    }
    public map<String,String> FileProperties()
    {
        map<String,string> FilePropertiesDetails = new map<String,string>();
         HttpRequest req2 = new HttpRequest();
        req2.setMethod('GET');
        req2.setEndpoint('https://www.googleapis.com/drive/v2/files');//+FolderId+'/childern');
        req2.setHeader('content-type','appliction/x-www-form-urlencoded');
        req2.setHeader('content-length','0');
        req2.setHeader('Authorization','Bearer'+''+access_token);
        req2.setTimeout(60*1000);
        Http h3 = new Http();
        system.debug('access token to get the files==========>'+access_token);
        
        HttpResponse res2 = h3.send(req2);
        system.debug('check the response query'+res2.getBody());
        JSONParser parser2 = JSON.createParser(res2.getBody());
        while (parser2.nextToken() != null)
        {
            string FileName='';
            String FileId ='';
            if((parser2.getCurrentToken() == JSONToken.FIELD_NAME))
            {
                if((parser2.getText()=='id'))
                {
                    parser2.nextToken();
                    FileId=parser2.getText();
                }
            
            parser2.nextToken();
            if((parser2.getText()=='name'))
            {
                parser2.nextToken();
                FileName=parser2.getText();   
            }
            FilePropertiesDetails.put(FileId, FileName);
            system.debug('the files in drive'+ FilePropertiesDetails.keyset());
                }
        }
        return FilePropertiesDetails;
    }
}