1

I'm stucked and confused on two reasons while doing a poc on integrating Salesforce with Eventbrite. How do i Save the token ? My authorization is successful and receiving access token as well.

My main motto is to create events in Salesforce and automatically gets creates on Eventbrite. Its a plain callout to learn webservices. This is what I am referring to https://www.eventbrite.com/developer/v3/

Apex Code

public class EventbriteCallBackController {

    public EventbriteCallBackController(){
        String clientId = 'Client_ID from app';
        String clientSecret = 'Client_Secret from app'; 

      String paramCode = ApexPages.currentPage().getParameters().get('code');
        system.debug('paramCode '+paramCode);

        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://www.eventbrite.com/oauth/token');
        String body = 'code='+paramCode+'&client_secret='+clientSecret+'&client_id='+clientId+'&grant_type=authorization_code';
        req.setMethod('POST');
        req.setBody(body);
        req.setHeader('Content-Type','application/x-www-form-urlencoded');
        System.debug('Request is' +req);
        HttpResponse res = new HttpResponse();
        System.debug('response is' +res.getBody());

        Http h1 = new Http();
        HttpResponse res2 = h1.send(req);
        String resp = res2.getBody();
        System.debug('FINAL RESP IS:'+EncodingUtil.urlDecode(resp, 'UTF-8'));

    }

}

Response

enter image description here

I got this response while hitting the url by "Allow" the authorization.

8
  • maybe a custom setting?
    – Eric
    Commented Oct 4, 2016 at 7:48
  • I created callbacktoken__c as a custom setting. How do i use this in my code.
    – JJoseph
    Commented Oct 4, 2016 at 8:00
  • You need to parse your response to get the access token and store it in custom setting. Post your sample respose too.
    – Reshma
    Commented Oct 4, 2016 at 8:41
  • @Reshma- added the response.
    – JJoseph
    Commented Oct 4, 2016 at 9:30
  • Response is in JSON format. So you can use JSONParser to get access token from response. Refer this developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
    – Reshma
    Commented Oct 4, 2016 at 11:20

1 Answer 1

2

Deserialize response

Map<string, object > results =Json.deserializeuntyped(response);

Then simply update your custom setting like another other object. Assuming it is a hierarchy type:

Customsetting__c cfg = customsetting.getorgdefaults();

cfg.field__c = (string)results.get('access_token');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .