cancel
Showing results for 
Search instead for 
Did you mean: 

getAuthorizationUrl() is success, but getAccessToken() is failed with exception 'Unauthorized'

SOLVED
Occasional Participant

getAuthorizationUrl() is success, but getAccessToken() is failed with exception 'Unauthorized'

Hello

 

I am working with Laravel, and I am using PHP API SDK - https://github.com/constantcontact/php-sdk.

 

And also I see this - http://developer.constantcontact.com/docs/authentication/oauth-2.0-server-flow.html.

 

Now I am trying to get access_token.

I saw this - https://github.com/constantcontact/php-sdk/blob/master/examples/getAccessToken.php, I am working based on this.

 

From $oauth->getAuthorizationUrl(); , it is successfully redirected to redirect_uri page.

And also i see code in url parameters there.

But when it called getAccessToken(), it is failed with exception 'Unauthorized'

 

This is my code.

 

$oauth = new CtctOAuth2($api_key, $api_secret, $redirect_uri);
$accessToken = $oauth->getAccessToken($code);
 
It is so simple. But it is failed.
 
Please let me know why it failed with 'Unauthorized', and how can I solve this?
 
Thanks much to anyone help!
6 REPLIES 6
Occasional Participant

Re: getAuthorizationUrl() is success, but getAccessToken() is failed with exception 'Unauthorized'

Nobody can help?

 

I get this code.

iuhYBa9Uv7oXt30WkEShBsl1OGZ

 

But I can't get access_token from it.

 

Maybe this code is invalid?

Moderator

Re: getAuthorizationUrl() is success, but getAccessToken() is failed with exception 'Unauthorized'

Hello @lara4,

 

Thank you for reaching out to Constant Contact's API Support.

 

If you are receiving an unauthorized error then either your API Key is not correct, or the username/password you are logging in with are not authorized to do what you are requesting. Since you are just trying to get an Access Token I would first try to use our API Tester page and see if you can get an Access Token with the same credentials there. https://constantcontact.mashery.com/io-docs

 

If you are still having problems I would suggest you email us at webservices@constantcontact.com so we can troubleshoot further as we may need some information that is best to not post here.

 

 


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

Re: getAuthorizationUrl() is success, but getAccessToken() is failed with exception 'Unauthorized'

@Jimmy_D, Thanks for your response.

 

I think it is related with redirect_uri.

I will see that.

 

Regards

Occasional Participant

Re: getAuthorizationUrl() is success, but getAccessToken() is failed with exception 'Unauthorized'

I found the reason myself.

It is from redirect uri paramter.

I used correct redirect uri, but with some parameter.

In this time, it was not working.

I fixed it by removing parameter.

 

Thanks

Moderator

Re: getAuthorizationUrl() is success, but getAccessToken() is failed with exception 'Unauthorized'

Hi @lara4,

 

Glad to hear that you got that figured out. For anyone else who may come across this post just keep in mind that the redirect URI must match exactly. That includes parameters as well.


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

Re: getAuthorizationUrl() is success, but getAccessToken() is failed with exception 'Unauthorized'

Hi, @Jimmy_D

 

Thanks!

 

Regard