Highlighted
Occasional Participant

C# Sample code

Hi,

 

I'm trying to implement the OAuth log in code for C# I know I need to pass redirect uri and API key somewhere somehow, but I'm not sure how. Can anyone post some sample code on just that part about how to  get that working?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: C# Sample code

Hi @OasisSeniorAdvisors,

 

If this response is coming back as null then you are most likely not submitting something correctly. At this step in the process you should have received a code from the first step and you are now exchanging that code for an Access Token. When you exchange the code for the Access Token you are sending along several bits of data for validation. You are sending your API Key, your client secret, the code you received in the previous step, and the redirect URI. If any of these do not match then you will not get an Access Token back.

 

You can log in to your Mashery account to check on your API Key, client secret, and redirect URI are correct. The code comes from the previous step.

 

A full explanation comes from here; check the "Access Token Request" section specifically. http://developer.constantcontact.com/docs/authentication/oauth-2.0-server-flow.html


Regards,
Jimmy D.
Tier II API Support Engineer

View solution in original post

6 REPLIES 6
Highlighted
Moderator

Re: C# Sample code

Hello,

 

Thank you for reaching out to the API Support team here at Constant Contact.

 

If you are not using a 3rd-party OAuth library, I'd recommend installing our C#/.NET wrapper. The README contains instructions and a code sample on how to set up OAuth to generate an access token. You can find it at https://github.com/constantcontact/.net-sdk

 

Please have a look and let me know if you have any questions!

 

Regards,
David B.
Tier II API Support Engineer

Highlighted
Occasional Participant

Re: C# Sample code

Thanks for the reply. I've sen that sample code.It uses winforms. I would need to use the webforms function to do my authentication. Do you have an example of that?

 

Or anyone. This is an open invitation.

Highlighted
Moderator

Re: C# Sample code

Hello @OasisSeniorAdvisors,

 

Did you notice the 2.2 section for webforms? It is buried down a bit farther so it can be harder to spot. Here is a direct link and hopefully this will be helpful. https://github.com/constantcontact/.net-sdk#22-for-web-forms


Regards,
Jimmy D.
Tier II API Support Engineer
Highlighted
Occasional Participant

Re: C# Sample code

Thanks. That moved me forward closer to where I want to be. I'm still experiencing an issue. In the API example the code to get the access token looks like

 

 _accessToken = OAuth.GetAccessTokenByCodeForWebApplication(HttpContext.Current, code);  

But the function I am able to call in my code looks a little different:      

 _accessToken = OAuth.GetAccessTokenByCode(HttpContext.Current, code);

 

Code is getting the value from the querystring that was returned when I chose allow. The token is still coming back as null. Am I making a mistake somewhere?

Highlighted
Moderator

Re: C# Sample code

Hi @OasisSeniorAdvisors,

 

If this response is coming back as null then you are most likely not submitting something correctly. At this step in the process you should have received a code from the first step and you are now exchanging that code for an Access Token. When you exchange the code for the Access Token you are sending along several bits of data for validation. You are sending your API Key, your client secret, the code you received in the previous step, and the redirect URI. If any of these do not match then you will not get an Access Token back.

 

You can log in to your Mashery account to check on your API Key, client secret, and redirect URI are correct. The code comes from the previous step.

 

A full explanation comes from here; check the "Access Token Request" section specifically. http://developer.constantcontact.com/docs/authentication/oauth-2.0-server-flow.html


Regards,
Jimmy D.
Tier II API Support Engineer

View solution in original post

Highlighted
Occasional Participant

Re: C# Sample code

That was the answer. Thank you. If anyone else is ever confused in the way that I was, you need to add the below to the appsettings in your webconfig

 

<add key="APIKey" value="yourkey"/>
<add key="RedirectURL" value="yoururl"/>
<add key ="ClientSecretKey" value="yoursecret"/>

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Register for our "Making Sense of Online Marketing for Retail" Webinar

Join us on Thursday, August 13th at 2pm ET for a free webinar where we'll discuss how to incorporate online marketing into your retail store.

Read More
Featured