Coder Social home page Coder Social logo

Working with Etsy Api - Example? about oauth-1.0a HOT 9 CLOSED

ddo avatar ddo commented on May 21, 2024
Working with Etsy Api - Example?

from oauth-1.0a.

Comments (9)

ddo avatar ddo commented on May 21, 2024

i tested, follow the below steps:

init

var request = require('request');
var OAuth   = require('oauth-1.0a');

var oauth = new OAuth({
    consumer: {
        public: 'xxx',
        secret: 'xxx'
    }
});

Obtaining Temporary Credentials - request token

var request_data = {
    url: 'https://openapi.etsy.com/v2/oauth/request_token?scope=email_r',
    method: 'POST'
};

request({
    url:    request_data.url,
    method: request_data.method,
    form:   oauth.authorize(request_data),
    json:   true //parse respone as json
}, function(err, res, data) {
    // {
    //     login_url: 'https://www.etsy.com/oauth/signin?oauth_consumer_key=xxx&oauth_token=xxx&service=v2_prod',
    //     oauth_token: 'xxx',
    //     service: 'xxx',
    //     oauth_token_secret: 'xxx',
    //     oauth_callback_confirmed: 'true',
    //     oauth_consumer_key: 'xxx',
    //     oauth_callback: 'oob'
    // }
}

access the login_url to get the credential (oauth_verifier)

var request_data = {
    url:    'https://openapi.etsy.com/v2/oauth/access_token',
    method: 'POST',
    data: {
        oauth_verifier: 'xxx'
    }
};

var token = {
    public: 'xxx',
    secret: 'xxx'
}

request({
    url:    request_data.url,
    method: request_data.method,
    form:   oauth.authorize(request_data, token)
}, function(err, res, data) {
    // oauth_token=xxx&oauth_token_secret=xxx
});

access the login_url to get the credential

Obtaining Token Credentials - access token

var request_data = {
    url: 'https://openapi.etsy.com/v2/oauth/access_token',
    method: 'POST',
    data: {
        oauth_verifier: 'xxx'
    }
};

var token = {
    public: 'xxx',
    secret: 'xxx'
}

request({
    url: request_data.url,
    method: request_data.method,
    form: oauth.authorize(request_data, token)
}, function(err, res, data) {
    // oauth_token=xxx&oauth_token_secret=xxx
});

Making an Authorized Request to the API - since you got the tokens you can use oauth-request to play around with the API

var request_data = {
    url: 'https://openapi.etsy.com/v2/users/__SELF__',
    method: 'GET'
};

var token = {
    public: 'xxx',
    secret: 'xxx'
}

request({
    url: request_data.url,
    qs: oauth.authorize(request_data, token),
    json: true
}, function(err, res, data) {
    // {
    //     count: 1,
    //     results: [{
    //         user_id: 53899516,
    //         login_name: 'ddooo',
    //         primary_email: '[email protected]',
    //         creation_tsz: 1411796074,
    //         referred_by_user_id: null,
    //         feedback_info: [Object],
    //         awaiting_feedback_count: 0
    //     }],
    //     params: {
    //         user_id: '__SELF__'
    //     },
    //     type: 'User',
    //     pagination: {}
    // }
});

from oauth-1.0a.

villanus avatar villanus commented on May 21, 2024

Sorry, I am not able to get this to work with Jquery Client side Javascript.
I get Access-Control-Origin header issues.

Here is what I have translated to client side Jquery code so far.

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha1.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
<script src="oauth.js"></script>


<script>
/*
var request = require('request');
var OAuth   = require('oauth-1.0a');
*/

var oauth = new OAuth({
    consumer: {
        public: 'xxx-keystring',
        secret: 'xxx-shared-secret'
    }
});

var request_data = {
    url: 'https://openapi.etsy.com/v2/oauth/request_token?scope=email_r',
    method: 'POST'
};

$.ajax({
    url: request_data.url,
    type: request_data.method,
      form:   oauth.authorize(request_data),
    json:   true //parse respone as json

}).done(function(err, response, data) {
    console.log(done);
});

</script>

from oauth-1.0a.

ddo avatar ddo commented on May 21, 2024

you can't do it on website, unless your client side is an extension or something else that allows cross domain requests

https://github.com/ddo/oauth-1.0a#client-side-usage-caution

from oauth-1.0a.

villanus avatar villanus commented on May 21, 2024

Makes total sense. I feel like an idiot. So I guess the only alternative is to create some sort of asp.net service or something to proxy the requests right?

from oauth-1.0a.

ddo avatar ddo commented on May 21, 2024

Only modern browsers disallow the cross domain requests, all the oauth request should be called on your server side, the client side just communicate with your server.

in your case:

etsy <--> your server <--> website

If your client side is not a website, you can send the cross domain i believe.
But you should do same as above since we can protect our secret key.

from oauth-1.0a.

villanus avatar villanus commented on May 21, 2024

Great. Let me look into this a bit. If i get a good proxy solution (php, asp) I will post my findings here.
Thank you so much in advance.

from oauth-1.0a.

villanus avatar villanus commented on May 21, 2024

So I disabled Cross Domain limitation in chrome, and now it seems like i can connect to etsy api just fine. (I know this is not good practice but for our needs its fine).

When I run the code above, etsy returns error 400.

from oauth-1.0a.

villanus avatar villanus commented on May 21, 2024

looks like they require SSL when trying to do this on the client. Going to try and do it via NginX reverse proxy and see if that gets us anywhere.

from oauth-1.0a.

ddo avatar ddo commented on May 21, 2024

sure :)

https://openapi.etsy.com/v2/oauth/

from oauth-1.0a.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.