PHP Classes

ETSY API OAUTH Problem

Recommend this page to a friend!

      PHP OAuth Library  >  All threads  >  ETSY API OAUTH Problem  >  (Un) Subscribe thread alerts  
Subject:ETSY API OAUTH Problem
Summary:I can't get ETSY receipt information.
Messages:7
Author:lan nguyen
Date:2016-05-24 07:44:03
 

  1. ETSY API OAUTH Problem   Reply   Report abuse  
Picture of lan nguyen lan nguyen - 2016-05-24 07:44:03
Hello, everybody

I got the trouble when i try to use ETSY API. This is my problem

I followed example here: http://www.phpclasses.org/package/7700-PHP-Authorize-and-access-APIs-using-OAuth.html#view_files/files/51685

That is really nice. Thanks so much. Those class so awesome. I run example code without issue. But when i try to get receipt, it's not luck. Let me explain

1. With this scope "$client->scope = 'transactions_r%20transactions_w' I got Invalid scope. How can i use for multiple scope?

2. I changed to single scope. I got this: "OAuth client error

Error: it was not possible to access the API call: it was returned an unexpected response status 404 Response: ':xxxyyyzzz' is not a valid shop name". That is a shopid, why it is saying shop name? Please help me to figure this out!!! Many thanks

My code:

$client->scope = 'transactions_r';
$receipt_status = "completed";
$altswag_shopid = "xxxyyyzzz";
$receip_url = "https://openapi.etsy.com/v2/shops/:{shop_id}/receipts/:{status}";
$receip_url_submit = str_replace("{status}",$receipt_status,$receip_url);
$receip_url_submit = str_replace("{shop_id}",$altswag_shopid,$receip_url_submit);

if(($success = $client->Initialize()))
{
if(($success = $client->Process()))
{
if(strlen($client->access_token))
{
$success = $client->CallAPI(
$receip_url_submit,
'GET', array(), array('FailOnAccessError'=>true), $user);
}
}
$success = $client->Finalize($success);
}


p/s: Sorry for my poor English.

  2. Re: ETSY API OAUTH Problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-05-24 17:53:49 - In reply to message 1 from lan nguyen
If you already obtained your token with the initial scope, you need to start over with the new scope. Call ResetAccessToken first to discard the old token.

Also I suspect that the list of scopes must be separated by spaces, not %20 . %20 is a space encoded with URLEncode which the class already calls.

  3. Re: ETSY API OAUTH Problem   Reply   Report abuse  
Picture of lan nguyen lan nguyen - 2016-05-25 06:57:05 - In reply to message 2 from Manuel Lemos
Thanks for your reply. It is a awesome experience. Thank you again

It is working now. I got Invalid 'shop name' error because wrong fetch url. My bad :(

Thank you again!!!

  4. Re: ETSY API OAUTH Problem   Reply   Report abuse  
Picture of lan nguyen lan nguyen - 2016-05-25 07:18:07 - In reply to message 2 from Manuel Lemos
Thanks for your help. My code works now. But I still have another problem. Let me explain it:

Are there any way to ignore 'Press button Allow Access' step, I mean grant access step??
I don't want to login press a button 'Allow Access' every time i run the code.
I'm going to make it running via cron. How can i do that?

I read from ETSY API, https://www.etsy.com/developers/documentation/getting_started/oauth.

But I find no way to do that.

  5. Re: ETSY API OAUTH Problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-05-25 19:11:02 - In reply to message 4 from lan nguyen
I am not sure what you mean but you do not need to obtain a new token every time you call the API.

You can just store the token in some storage container, like a database, and make calls even when the user is not present.

If that is what you mean, there is a subclass that can be used to store tokens in databases instead of sessions.

Read this article for more details:

phpclasses.org/blog/package/7700/po ...

  6. Re: ETSY API OAUTH Problem   Reply   Report abuse  
Picture of lan nguyen lan nguyen - 2016-05-26 08:40:51 - In reply to message 5 from Manuel Lemos
You are so nice. I will take a look that article. Maybe that is what I want to.
Thank for you help.

  7. Re: ETSY API OAUTH Problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-05-26 18:26:05 - In reply to message 6 from lan nguyen
No problem. Being able to make calls without the user presence is what many users of this class need because they have automated scripts that run in the background but they have to get the tokens first on the Web with the user presence.

There are however other alternatives for the case when you want to use an administrative account. In that case there are other modes the OAuth class can work.

I have not checked the ETSY API specifically. But if that is the case, just let me know where in the documentation it recommends those modes.