Home » Php » php – Fatal Error when implementing an OAuth library to connect to an ETSY store

php – Fatal Error when implementing an OAuth library to connect to an ETSY store

Posted by: admin July 12, 2020 Leave a comment

Questions:

I am using an OAuth library to connect to my Etsy store (etsy.com) and try to retrieve some information regarding sold orders.

This is the library: https://github.com/Lusitanian/PHPoAuthLib/blob/master/examples/etsy.php

However, I keep getting an error after I “Allow Access”. I receive a token but when I allow access the issue is happening.

Here is the full error:

  Fatal error: Uncaught exception 'OAuth\Common\Http\Exception\TokenResponseException' with message 'file_get_contents(http://openapi.etsy.com/v2/private/users/__SELF__): failed to open stream: HTTP request failed! 
HTTP/1.1 400 Bad Request ' in /hermes/bosoraweb013/b1151/ipg.tahara/APIs/PHPoAuthLib-master/src/OAuth/Common/Http/Client/StreamClient.php:70 Stack trace: #0 /hermes/bosoraweb013/b1151/ipg.tahara/APIs/PHPoAuthLib-master/src/OAuth/OAuth1/Service/AbstractService.php(137): 
OAuth\Common\Http\Client\StreamClient->retrieveResponse(Object(OAuth\Common\Http\Uri\Uri), NULL, Array, 'GET') #1 /hermes/bosoraweb013/b1151/ipg.tahara/APIs/PHPoAuthLib-master/examples/etsy.php(47): 
OAuth\OAuth1\Service\AbstractService->request('/private/users/...') #2 {main} thrown in /hermes/bosoraweb013/b1151/ipg.tahara/APIs/PHPoAuthLib-master/src/OAuth/Common/Http/Client/StreamClient.php on line 70

Would anyone have any input to identify what the issue is?

How to&Answers:

The error is telling you that the library was getting back a 400 error which means that the server does not like your request. If this is something that might happen more often than not then a try catch block is your friend if only to terminate gracefully and perhaps log the problem.

If this was me I would have the error, the request and the Library object print_r inside a tag or into a text document so I could get a better idea of what was going on.

I’d be wondering if this was an authentication issue, a need to use HTTPS rather than HTTP, a bug in the library, an end-point issue or just some bad data at some place or other. The more information you have and the more you can isolate and confirm as working the faster I could home in on the problem.

I wish you the best of luck debugging and tracing the fault. I know how insanely frustrating these things can be.