Ready-to-use PHP code to retrieve receipts info from ETSY store (using OAuth)

1,234 views
Skip to first unread message

Samuel Benolol

unread,
Jan 2, 2014, 11:48:09 AM1/2/14
to etsy-...@googlegroups.com
I am looking for a ready to use PHP code to retrieve receipts information from sold orders from my ETSY store. My issue is I am not able to implement de OAuth part.

I just want a code where I can put in my secret and key and start retrieving information from the store.

Anyone please?

david olick

unread,
Jan 2, 2014, 1:20:10 PM1/2/14
to Etsy API V2
OAuth is an essential part of the API when accessing private data.  If you can use PHP, why can't you use/implement OAuth?



--
David Olick
Oriku Inc.


--
You received this message because you are subscribed to the Google Groups "Etsy API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to etsy-api-v2...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Samuel Benolol

unread,
Jan 2, 2014, 1:43:30 PM1/2/14
to etsy-...@googlegroups.com, david...@gmail.com
I have a code as below, but I am not sure where that class OAuth should be defined. Any link to download the full library so I can use it in my host server by just calling it with "new"?

define('OAUTH_CONSUMER_KEY', 'key);
define('OAUTH_CONSUMER_SECRET', 'secret');
$oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
$req_token = $oauth->getRequestToken("http://openapi.etsy.com/v2/sandbox/oauth/request_token",
'oob');
print_r($req_token);

$login_url = sprintf(
  "%s?oauth_consumer_key=%s&oauth_token=%s",
  $req_token['login_url'],
  $req_token['oauth_consumer_key'],
  $req_token['oauth_token']
);
print "go to this url: ".$login_url."\n";
print "then tell me what the verifier code you get back is: \n";

$handle = fopen("php://stdin","r");
$line = fgets($handle);

$request_token = $req_token['oauth_token'];
$request_token_secret = $req_token['oauth_token_secret'];
$verifier = trim($line);

print "you said {$verifier}\n";
print "now let's see what we can get back from Etsy...";

$oauth->setToken($request_token, $request_token_secret);

try {
  $access_token =
null, $verifier);
} catch (OAuthException $e) {
  print_r($e->getMessage());
}

$oauth_token = $access_token['oauth_token'];
$oauth_token_secret = $access_token['oauth_token_secret'];

$oauth->setToken($oauth_token, $oauth_token_secret);

try {
  $json = $oauth->getLastResponse();
  print_r(json_decode($json, true));

} catch (OAuthException $e) {
  error_log($e->getMessage());
  error_log(print_r($oauth->getLastResponse(), true));
  error_log(print_r($oauth->getLastResponseInfo(), true));
  exit;

david olick

unread,
Jan 2, 2014, 1:53:31 PM1/2/14
to Samuel Benolol, Etsy API V2
I don't use PHP myself, but there's sample code on Etsy's site that uses PHP:


// instantiate the OAuth object
// OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET are constants holding your key and secret
// and are always used when instantiating the OAuth object 
$oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);

// make an API request for your temporary credentials
$req_token = $oauth->getRequestToken("https://openapi.etsy.com/v2/oauth/request_token?scope=email_r%20listings_r", 'oob');

print $req_token['login_url']."\n";


--
David Olick
Oriku Inc.


Samuel Benolol

unread,
Jan 2, 2014, 3:43:07 PM1/2/14
to etsy-...@googlegroups.com, Samuel Benolol, david...@gmail.com
In order to instantiate the OAuth object (new OAuth) I assume the library has to be present in the server. Where could I download the OAuth library so I could upload it to my FTP and then instantiate it?

david olick

unread,
Jan 2, 2014, 5:08:31 PM1/2/14
to Samuel Benolol, Etsy API V2
The Etsy link I gave you above linked to this: http://us.php.net/oauth

Have you tried following those instructions to install oauth?


--
David Olick
Oriku Inc.


Samuel Benolol

unread,
Jan 2, 2014, 5:12:11 PM1/2/14
to etsy-...@googlegroups.com, Samuel Benolol, david...@gmail.com
Yes, the installation of that link is done with PECL, which my server and many others don't support (http://us.php.net/manual/en/oauth.installation.php). So that option is not good for many.
I am looking for an integrated OAuth library I can upload via ftp and then start calling from it...
Reply all
Reply to author
Forward
0 new messages