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
VICKY_SFDCVICKY_SFDC 

Not Getting The Request Token While Integration With Box.com ,,, i am posting the complete code

APEX:

public class OAuth_Box_Example {
    public Mydata__c data         {set;get;}
    public String code             {set;get;}
    public String accessToken       {set;get;}
    public String result             {set;get;}
    public String callbackurl         {set;get;}
    
    public  OAuth_Box_Example(){
        data=[Select id,ClientId__c,ClientSecret__c from Mydata__c where name='Box'];
        callbackurl='https://ap16.salesforce.com/apex/BoxResponse';
    }
    
    public PageReference requestCode(){
        String url='https://account.box.com/api/oauth2/authorize?';
        url=url+'response_type=code&client_id='+data.clientId__c;
        url=url+'&redirect_uri='+callbackurl;
        url=url+'&state=Vikas';
        PageReference p=new PageReference(url);
        return p;
    }
    
    public void readCode(){
        code=Apexpages.currentPage().getParameters().get('code');
    }
    public void requestToken(){
        String url='https://api.box.com/oauth2/token';        
        Http p=new Http();
        HttpRequest request=new HttpRequest();
        request.setEndpoint(url);
        request.setMethod('POST');
        String body='grant_type=autherization_code&code='+code;
        body=body+'&client_id='+data.ClientId__c;
        body=body+'&client_secret='+data.ClientSecret__c;
        request.setBody(body);
        HttpResponse response=p.send(request);
        String jsonBody=response.getBody();
        System.JSONParser jp=JSON.createParser(jsonBody);
        while(jp.nextToken()!=null){
            if(jp.getText()=='access_token'){
                jp.nextToken();
                accessToken=jp.getText();
            }
        }
        
    }    
}

VISUAL FORCE:

1) BoxResponse:

<apex:page controller="OAuth_Box_Example" action="{!readCode}">
    <apex:form >
        <apex:pageBlock title="Token & Action" id="pb">
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Token" action="{!requestToken}" reRender="pb"/>
            </apex:pageBlockButtons>
            Client Id:{!data.ClientId__c}<br/><br/>
            CallbackSecret:{!data.ClientSecret__c}<br/><br/>
            RedirectUrl:{!callbackurl}<br/><br/>
            Code:{!code}<br/><br/>
            AccessToken:{!accessToken}
        </apex:pageBlock>
    </apex:form>
</apex:page>


2)Box_Home:

<apex:page controller="OAuth_Box_Example">
    <apex:form >
        <apex:pageBlock title="OAuth">
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Submit" action="{!requestCode}"/>
            </apex:pageBlockButtons>
            Client Id:{!data.ClientId__c}<br/><br/>
            CallbackUrl:{!callbackurl}<br/><br/>
            State : Vikas
        </apex:pageBlock>
    </apex:form>
</apex:page>
SwethaSwetha (Salesforce Developers) 
HI Vicky,
Are you seeing any error message while fetching the request token?Thanks
VICKY_SFDCVICKY_SFDC
No
hd sdhd sd
What you are saying is ask for it once, keep it in my org (perhaps on a custom placing) and use it once more? What if I want to get admission with prolulubox (https://proluluboxapk.com/) program to completely new Org with sandboxes? Still keep them sameway?