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!

21 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
  8. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.

    Best Linux training in Noida
    Linux Training Institute in Noida

    ReplyDelete
  9. The information which you have provided is very good. It is very useful who is looking for salesforce Online course Hyderabad

    ReplyDelete
  10. wihh nice info
    kunjung balik, di web kami banyak penawaran dan tips tentang kesehatan
    Ada artikel menarik tentang obat tradisional yang mampu menyembuhkan penyakit berat, cek yuk
    Obat tradisional Sinusitis
    Obat tradisional Keloid
    Obat tradisional Asam Lambung

    ReplyDelete
  11. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    Java training in Chennai | Java training in Annanagar | Java training in Chennai

    Java training in Chennai | Java training in Electronic city

    ReplyDelete
  12. Really you have done great job,There are may person searching about that now they will find enough resources by your post
    online Python training | python training in chennai | Python training course in Chennai

    ReplyDelete
  13. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    Best Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

    ReplyDelete
  14. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 

    rpa online training |
    rpa course in bangalore |
    rpa training in bangalore |
    rpa training institute in bangalore

    ReplyDelete
  15. This is ansuperior writing service point that doesn't always sink in within the context of the classroom. In the first superior writing service paragraph you either hook the reader's interest or lose it. Of course your teacher, who's getting paid to teach you how to write an good essay, 
    Data Science course in rajaji nagar | Data Science with Python course in chenni

    Data Science course in electronic city | Data Science course in USA

    Data science course in pune | Data Science Training institute in Pune | Data science course in kalyan nagar | Data Science Course in Bangalore

    ReplyDelete

  16. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.


    AWS Training in chennai | Best AWS Course in Velachery,Chennai

    Best AWS Training in Chennai | AWS Training Institutes |Chennai,Velachery

    Amazon Web Services Training in Anna Nagar, Chennai |Best AWS Training in Chennai

    ReplyDelete