Feb 23, 2015

MailChimp Authentication In Salesforce - Easy Steps (Authentication Part 3)

I hope following post might have helped you in authentication:


So here is the third part of the series, authentication with MailChimp

The whole process of authentication with Mailchimp is divided into some simple steps :

Step 1:- First of all to authenticate with Mailchimp, you must have an account on Mailchimp if not then sign up here.

Step 2:- Now create an app by selecting your name under the logo and select account.


Step 3:- Here as you can see in the given image below, select registered app and register an app here.


Step 4:- Once you've entered the details for your Company and Application and saved them, your client_id and client_secret will be displayed at the bottom of the "edit" page for your application.

Note: - Keep in mind that Redirect Uri is the Uriof your page where you want to be redirected with the "code" parameter.

Step 5:- Now create an apex class and paste the below code in it.


publicwithsharingclassMailChimpIntegrationController
{
 public string client_id = 'Your ClientId';
 public string client_secret = 'Your ClientSecret';
 public string authorize_uri = 'https://login.mailchimp.com/oauth2/authorize';
 public string redirect_uri = 'https://c.na15.visual.force.com/apex/MailChimpIntegrationPage';
 
 publicMailChimpIntegrationController()
 {}
 
 publicPagereferenceauthorizeMailChimp()
 {
  authorize_uri = authorize_uri + '?response_type=code&client_id=' + client_id + '&redirect_uri=' + Encodingutil.urlEncode(redirect_uri , 'UTF-8');
PageReferencepg = newPageReference(authorize_uri) ;  
returnpg ;
 }
 
 publicvoidmailChimpAccessToken()
 {
  string code = ApexPages.currentPage().getParameters().get('code') ;  
  HttpRequestreq = newHttpRequest();  
req.setMethod('POST');  
req.setEndpoint('https://login.mailchimp.com/oauth2/token'); 
req.setHeader('content-type', 'application/x-www-form-urlencoded'); 
req.setHeader('Accept', 'application/json'); 
        String messageBody = 'grant_type=authorization_code&client_id=' + client_id + '&client_secret=' + client_secret + '&code=' + code + '&redirect_uri=' + Encodingutil.urlEncode(redirect_uri , 'UTF-8');
req.setHeader('Content-length', String.valueOf(messageBody.length()));  
req.setBody(messageBody);  
req.setTimeout(60*1000);  

        Http h = newHttp();  
        String resp;  
HttpResponse res = h.send(req);  
resp = res.getBody(); 

system.debug('+++++----json---with---Access-----token----++++++'+resp);
 }
}


Step 6:- Now create a visualforce page and paste the below code in it.



 
   
   
 


Step 7:- At last create a new remote site setting with value as below

-> Remote Site Name : MailChimp
-> Remote Site URL : https://login.mailchimp.com
-> Active : True


I hope now you can manipulate the code according to the need. As these simple buttons on VFP shows you how to authenticate and get the access tokens.

Cheers!

9 comments:

  1. hi
    I am Soma . I understand that you are excellent in integration. In my application,if i call the same method to connect different web services , will it affect the performance? The number of connection to web service per day may exceed 2000 times and we are using unlimited version.
    Shall i keep separate method to connect each web services? which is the best way to do web service? please advise.
    thanks

    ReplyDelete
  2. Thanks for your informative article. Your pose helped me a lot to under the future in .Net mobile application development. .NET Training in Chennai

    ReplyDelete
  3. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Regards,

    Python Training in Chennai|Python Classes in Chennai|Python Course in Chennai

    ReplyDelete
  4. Very informative blog and very useful article thank you for sharing with us , keep posting learn more about salesforce training,salesforce online training

    ReplyDelete
  5. This is very helpful post its about latest apps thanks amazing sharing keep sharing..
    selenium training in chennai

    ReplyDelete
  6. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information&its very useful to me...
    Android training in chennai
    Ios training in chennai

    ReplyDelete
  7. Thanks for sharing informative article. Download Windows 7 ultimate for free from getintopc. It helps you to explore full functionality of windows operating system.

    ReplyDelete