Advertisement
roland_b70

etsyTest

Jul 16th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. Making an Authorized Request to the API
  2.  
  3. You can use the OAuth token credentials from the previous steps to make calls for that authenticated member. The setToken() call will now set these final tokens and make the call to the Etsy API. In the URL here, __SELF__ is shorthand for the logged-in member's ID. The API will fill that in for you.
  4.  
  5. $access_token = // get from db
  6. $access_token_secret = // get from db
  7.  
  8. $oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET,
  9.                   OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
  10. $oauth->setToken($access_token, $access_token_secret);
  11.  
  12. try {
  13.    $data = $oauth->fetch("https://openapi.etsy.com/v2/users/__SELF__", null, OAUTH_HTTP_METHOD_GET);
  14.    $json = $oauth->getLastResponse();
  15.    print_r(json_decode($json, true));
  16.    
  17. } catch (OAuthException $e) {
  18.    error_log($e->getMessage());
  19.    error_log(print_r($oauth->getLastResponse(), true));
  20.    error_log(print_r($oauth->getLastResponseInfo(), true));
  21.    exit;
  22. }
  23.  
  24. The token credentials you receive for a member's account do not expire, and can be used over and over again to make authenticated API requests. You should keep the token secret in a secure location and never send it as a plaintext parameter (it's only used for signing your requests, and never needs to be sent in an API request on its own.) You will not need to step the Etsy member through the OAuth authorization again; unless she or he decides to revoke access for your application, or you unless you add features to your app that require additional permission scopes. In these cases, you will need to discard your old token credentials and obtain new ones for the member.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement