8

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?

user2509541
  • 268
  • 4
  • 14
  • 2
    The message tells you what you need to know. The HTTP request gave `400 Bad Request`. This tells you two things, first you have an invalid request for some reason (check against API documentation) and second, you should probably be executing this code in a try/catch block so you can handle such Exceptions. – Mike Brant Jan 24 '14 at 18:34
  • 2
    This sounds like you're trying to connect to HTTP and needs to connect to HTTPS. If that's the case, the info should be in the response header, but just switching to HTTPS might be an easier way to check it. – samyb8 Jan 24 '14 at 18:47
  • @MikeBrant I am just using the request in the library (the one in the link I provided). How could I solve this? – user2509541 Jan 27 '14 at 21:40
  • 1
    Looks like [this commit](https://github.com/Lusitanian/PHPoAuthLib/commit/34d308c5070384bdb483c59da06ae11510caa397#diff-a7284ea9fd5d66fde2c570220e0b3d47) should fix that. If this indeed is the issue it will be resolved once we tag the next version (which will be soonish). – PeeHaa Feb 16 '14 at 21:17

1 Answers1

0

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.