inakiabt / etsy-php

Etsy API wrapper for PHP
74 stars 59 forks source link

scripts/auth-setup.php throws EtsyRequestException #39

Closed quape closed 6 years ago

quape commented 6 years ago

Hi there! I used this script before and it worked just fine but today I'm getting this strange error. Any ideas? It happens within getAccessToken() of OAuthHelper.

Etsy\EtsyRequestException: [1]: Invalid auth/bad request (got a 411, expected HTTP/1.1 20X or a redirect): Array#012(#012)#012<!DOCTYPE html>#012<html lang=en>#012 <meta charset=utf-8>#012 <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">#012 <title>Error 411 (Length Required)!!1</title>#012 <style>#012 *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}#012 </style>#012 <a href=//www.google.com/><span id=logo aria-label=Google></span></a>#012 <p><b>411.</b> <ins>That’s an error.</ins>#012 <p>POST requests require a <code>Content-length</code> header. <ins>That’s all we know.</ins>

garislangit commented 6 years ago

I was having the same problem , actually there is no problem with this library itself. It seems etsy open api server is using google cloud now. oauth pecl extension version 2.x (PHP 7+) lacks of content-length header that required by google cloud server. hence it does not work properly. However this library works fine with oauth pecl extension version 1.2.3 (PHP 5.4-5.6) .

quape commented 6 years ago

Great you found a solution. What worked for me was using the node library etsy-js for doing the oauth handshake and creating the token and token_secret. With these I was able to use etsy-php like normal.

chrismeats commented 6 years ago

Hey guys, I am having this same issue and having a hard time getting around it. I dont really want to have to use another is library to solve this. Is there an easier solution on PHP 7 and oauth v 2.0.2

image

garislangit commented 6 years ago

I contacted etsy developer support a few weeks ago. here's the answer, hopefully it can be easier solution without having to change oauth library :

Due to recent updates, you will now have to specify the GET method when using Oauth. Here's an example:

$req_token = $oauth->getRequestToken("https://openapi.etsy.com/v2/oauth/request_token?scope=email_r%20listings_r", 'oob', "GET");

$acc_token = $oauth->getAccessToken("https://openapi.etsy.com/v2/oauth/access_token", null, $verifier, "GET");

i have tried, and it worked fine with php 7 + oauth 2.2