|
Hi Team,
Does anyone experienced aweber API using java/Grails, I’m working on it to connect aweber API using HTTPbuilder but no luck, it throws me below exception. {"error": {"status": 400, "documentation_url": "https://labs.aweber.com/docs/troubleshooting#badrequest", "message": "Request does not have OAuth credentials. https://labs.aweber.com/docs/troubleshooting#badrequest", "type": "BadRequestError"}} Here is the code I’m using to get request token as stated in this document https://labs.aweber.com/docs/authentication def appKey ="AkUepX8nQhlK8OgUqZ3BHSTR" def appSecret ="JrI6iP2MFq59hreblyrRIhQpoAacg1scrB54VAWT" int millis = (int) System.currentTimeMillis() * -1; int time = (int) millis / 1000; def jsonMap = [ ["oauth_consumer_key": "${appKey}"], ["oauth_nonce": "510a6d6f0e4fb70b72096ce48cb22af8"], ["oauth_signature": "uvNa27v1uyVES37VfsX2Tj1OUYU="], ["oauth_signature_method": "HMAC-SHA1"], ["oauth_timestamp": String.valueOf(time)], ["oauth_version": "1.0"] ] def url = "https://auth.aweber.com/1.0/oauth/request_token" def http = new HTTPBuilder(url); http.auth.basic appKey, appSecret http.request( Method.POST, JSON ) { req -> requestContentType = "application/json" body = jsonMap response.success = { resp, json -> println "Successful fetching!" } response.error = { resp, json -> log.error("Ouch on fetching" + json); } } It would be appreciated anyone review my code and guide me to resolve the issue or if there is any other way to do this. Thanks in advance Lok
Cheers,
Lok
|
|
It looks like you are just copy and pasting the signature from the
documentation, whereas you are supposed to generate a new signature based on the request according to oAuth rules. It says so under 'oauth_signature' in the documentation you just provided. The HttpBuilder has a good example of oAuth using Signpost - http://groovy.codehaus.org/modules/http-builder/doc/auth.html And there is another good oAuth java library called Scribe - https://github.com/fernandezpablo85/scribe-java Maybe you want to use those instead of generating your own solution. ( Look into Scribe's source code to see how signature is generated - https://github.com/fernandezpablo85/scribe-java/blob/master/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java ). On Tue, Jul 24, 2012 at 6:54 AM, Lok@sigma <[hidden email]> wrote: > Hi Team, > Does anyone experienced aweber API using java/Grails, > I’m working on it to connect aweber API using HTTPbuilder but no luck, it > throws me below exception. > {"error": {"status": 400, "documentation_url": > "https://labs.aweber.com/docs/troubleshooting#badrequest", "message": > "Request does not have OAuth credentials. > https://labs.aweber.com/docs/troubleshooting#badrequest", "type": > "BadRequestError"}} > Here is the code I’m using to get request token as stated in this document > https://labs.aweber.com/docs/authentication > def appKey ="AkUepX8nQhlK8OgUqZ3BHSTR" > def appSecret ="JrI6iP2MFq59hreblyrRIhQpoAacg1scrB54VAWT" > > int millis = (int) System.currentTimeMillis() * -1; > int time = (int) millis / 1000; > > def jsonMap = [ > ["oauth_consumer_key": "${appKey}"], > ["oauth_nonce": "510a6d6f0e4fb70b72096ce48cb22af8"], > ["oauth_signature": "uvNa27v1uyVES37VfsX2Tj1OUYU="], > ["oauth_signature_method": "HMAC-SHA1"], > ["oauth_timestamp": String.valueOf(time)], > ["oauth_version": "1.0"] > ] > def url = "https://auth.aweber.com/1.0/oauth/request_token" > def http = new HTTPBuilder(url); > http.auth.basic appKey, appSecret > http.request( Method.POST, JSON ) { req -> > requestContentType = "application/json" > body = jsonMap > response.success = { resp, json -> > println "Successful fetching!" > } > > response.error = { resp, json -> > log.error("Ouch on fetching" + json); > } > } > It would be appreciated anyone review my code and guide me to resolve the > issue or if there is any other way to do this. > > Thanks in advance > Lok > > > > > ----- > Cheers, > Lok > -- > View this message in context: http://grails.1312388.n4.nabble.com/Connect-to-aweber-API-using-java-Grails-tp4632082.html > Sent from the Grails - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Thanks Tomas, It looks like you are just copy and pasting the signature from the
Cheers,
Lok
|
|
Hi Lok,
You might want to try my grails oauth plugin which should look after all of the authentication and communication for you. It uses the scribe library which Tomas talks about. http://grails.org/plugin/oauth Cheers, Antony On 30 July 2012 07:08, Lok@sigma <[hidden email]> wrote: > Thanks Tomas, > I tried by generating random strings, let me try with below references. > > Thanks > Lok > > On Mon, Jul 30, 2012 at 6:13 AM, tomas lin [via Grails] <[hidden email]> > wrote: >> >> It looks like you are just copy and pasting the signature from the >> documentation, whereas you are supposed to generate a new signature >> based on the request according to oAuth rules. It says so under >> 'oauth_signature' in the documentation you just provided. >> >> The HttpBuilder has a good example of oAuth using Signpost - >> http://groovy.codehaus.org/modules/http-builder/doc/auth.html >> >> And there is another good oAuth java library called Scribe - >> https://github.com/fernandezpablo85/scribe-java >> >> Maybe you want to use those instead of generating your own solution. ( >> Look into Scribe's source code to see how signature is generated - >> >> https://github.com/fernandezpablo85/scribe-java/blob/master/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java >> ). >> >> >> >> On Tue, Jul 24, 2012 at 6:54 AM, Lok@sigma <[hidden email]> wrote: >> >> > Hi Team, >> > Does anyone experienced aweber API using java/Grails, >> > I’m working on it to connect aweber API using HTTPbuilder but no luck, >> > it >> > throws me below exception. >> > {"error": {"status": 400, "documentation_url": >> > "https://labs.aweber.com/docs/troubleshooting#badrequest", "message": >> > "Request does not have OAuth credentials. >> > https://labs.aweber.com/docs/troubleshooting#badrequest", "type": >> > "BadRequestError"}} >> > Here is the code I’m using to get request token as stated in this >> > document >> > https://labs.aweber.com/docs/authentication >> > def appKey ="AkUepX8nQhlK8OgUqZ3BHSTR" >> > def appSecret ="JrI6iP2MFq59hreblyrRIhQpoAacg1scrB54VAWT" >> > >> > int millis = (int) System.currentTimeMillis() * -1; >> > int time = (int) millis / 1000; >> > >> > def jsonMap = [ >> > ["oauth_consumer_key": "${appKey}"], >> > ["oauth_nonce": "510a6d6f0e4fb70b72096ce48cb22af8"], >> > ["oauth_signature": "uvNa27v1uyVES37VfsX2Tj1OUYU="], >> > ["oauth_signature_method": "HMAC-SHA1"], >> > ["oauth_timestamp": String.valueOf(time)], >> > ["oauth_version": "1.0"] >> > ] >> > def url = "https://auth.aweber.com/1.0/oauth/request_token" >> > def http = new HTTPBuilder(url); >> > http.auth.basic appKey, appSecret >> > http.request( Method.POST, JSON ) { req -> >> > requestContentType = "application/json" >> > body = jsonMap >> > response.success = { resp, json -> >> > println "Successful fetching!" >> > } >> > >> > response.error = { resp, json -> >> > log.error("Ouch on fetching" + json); >> > } >> > } >> > It would be appreciated anyone review my code and guide me to resolve >> > the >> > issue or if there is any other way to do this. >> > >> > Thanks in advance >> > Lok >> > >> > >> > >> > >> > ----- >> > Cheers, >> > Lok >> > -- >> > View this message in context: >> > http://grails.1312388.n4.nabble.com/Connect-to-aweber-API-using-java-Grails-tp4632082.html >> > Sent from the Grails - user mailing list archive at Nabble.com. >> > >> > --------------------------------------------------------------------- >> > To unsubscribe from this list, please visit: >> > >> > http://xircles.codehaus.org/manage_email >> > >> > >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> >> >> ________________________________ >> If you reply to this email, your message will be added to the discussion >> below: >> >> http://grails.1312388.n4.nabble.com/Connect-to-aweber-API-using-java-Grails-tp4632082p4632399.html >> To unsubscribe from Connect to aweber API using java/Grails, click here. >> NAML > > > Cheers, Lok > > ________________________________ > View this message in context: Re: Connect to aweber API using java/Grails > > Sent from the Grails - user mailing list archive at Nabble.com. -- ________________________________ ꜽ . antony jones . http://www.enzy.org --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
