Search code examples
apicoldfusionetsy

etsy API with coldfusion


trying to request_login with ETSY api but nothing seems working ....

https://openapi.etsy.com/v2/oauth/request_token?oauth_consumer_key=a93ays32uckifw3k0lrsfy2n&oauth_nonce=82asXUrVrwV&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1416562333&oauth_version=1.0&oauth_signature=mBhVKblbSBes1f3AkvaJmjJSJ24=

oauth_consumer_key = a93ays32uckifw3k0lrsfy2n
oauth_nonce = 82asXUrVrwV
oauth_signature_method = HMAC-SHA1
oauth_timestamp = 1416562333
oauth_version = 1.0
oauth_signature = mBhVKblbSBes1f3AkvaJmjJSJ24=

please suggest how to proceed

i tried below code

<cfset tc = CreateObject("java", "java.util.Date").getTime()>
<cfset otimeStamp = Int(tc / 1000)>

<cfset iMin = 0>
<cfset iMax = CreateObject("java","java.lang.Integer").MAX_VALUE>
<cfset sToEncode = otimeStamp & RandRange(iMin, iMax)>
<cfset onounce =  Hash(sToEncode, "SHA")/>

<cffunction name="hmacEncrypt" returntype="binary" access="public" output="false">
    <cfargument name="signKey" type="string" required="true" />
    <cfargument name="signMessage" type="string" required="true" />
    <cfset var jMsg = JavaCast("string",arguments.signMessage).getBytes("iso-8859-1") />
    <cfset var jKey = JavaCast("string",arguments.signKey).getBytes("iso-8859-1") />
    <cfset var key = createObject("java","javax.crypto.spec.SecretKeySpec") />
    <cfset var mac = createObject("java","javax.crypto.Mac") />
    <cfset key = key.init(jKey,"HmacSHA1") />
    <cfset mac = mac.getInstance(key.getAlgorithm()) />
    <cfset mac.init(key) />
    <cfset mac.update(jMsg) />
    <cfreturn mac.doFinal() />
</cffunction>

<cfset result = hmacEncrypt("a93ays32uckifw3k0lrsfy2n", "GET&https%3A%2F%2Fopenapi.etsy.com%2Fv2%2Foauth%2Frequest_token&oauth_consumer_key%3Da93ays32uckifw3k0lrsfy2n%26oauth_nonce%3D#onounce#%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D#otimeStamp#%26oauth_version%3D1.0")>
<cfset osign = toString(tobase64(result))>

<cfhttp url="https://openapi.etsy.com/v2/oauth/request_token?oauth_consumer_key=a93ays32uckifw3k0lrsfy2n&oauth_nonce=#onounce#&oauth_signature_method=HMAC-SHA1&oauth_timestamp=#otimeStamp#&oauth_version=1.0&oauth_signature=#osign#">
        <cfhttpparam type="header" name="shop_id" value="cfdevshop">
        <cfhttpparam type="header" name="GData-Version" value="3">
</cfhttp>
<cfdump var="#cfhttp#">

Solution

  • Done Etsy Oauth Authentication successfully using this package http://oauthconsumer.riaforge.org/