我正试图在Etsy上创建一个新列表。
-
我使用oauth进行身份验证,得到
OAUTH_CONSUMER_KEY
和OAUTH_CONSUMER_SECRET
-
我用这段代码检查了一下,得到了所有卖家数据的返回日志,所以OAuth一切正常。
$oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); $oauth->setToken("key","secret"); try { $data = $oauth->fetch("http://openapi.etsy.com/v2/users/__SELF__", null, OAUTH_HTTP_METHOD_GET); $json = $oauth->getLastResponse(); print_r(json_decode($json, true)); } catch (OAuthException $e) { error_log($e->getMessage()); error_log(print_r($oauth->getLastResponse(), true)); error_log(print_r($oauth->getLastResponseInfo(), true)); exit; }
-
我正试图把一个新的物品装箱。首先,我设法通过产品上的api浏览器创建了一个新的列表。现在,我想通过PHP创建一个新的列表。这就是我所做的,它返回了我的错误:
这是我的代码:
$oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET,OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->setToken("key","secret");
try {
$url = "http://openapi.etsy.com/v2/listings";
$params = array('description' => 'thisisdesc','materials' => 'yes','price'=>"5.99"
,'quantity'=>"2",'shipping_template_id'=>"52299",'shop_section_id'=>"1"
,'title'=>"thisistitle",'category_id'=>"i_did",'who_made'=>"5.99"
,'is_supply'=>"1",'when_made'=>"2010_2012");
$oauth->fetch($url, $params, OAUTH_HTTP_METHOD_POST);
print_r(json_decode($json, true));
} catch (OAuthException $e) {
print_r($e);
error_log($e->getMessage());
error_log(print_r($oauth->getLastResponse(), true));
error_log(print_r($oauth->getLastResponseInfo(), true));
exit;
}
我得到的回复是:
Invalid auth/bad request (got a 403, expected HTTP/1.1 20X or a redirect)
This method not accessible to restricted API key.
如果您仍在开发应用程序,则只要商店在您的帐户上,您就可以创建列表,而无需获得API的完全访问权限。在发出第一个OAUTH请求时,请确保在listings_w
中解析为权限范围。我在下面的代码中修改了ETSY提供的示例。
// instantiate the OAuth object
// OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET are constants holding your key and secret
// and are always used when instantiating the OAuth object
$oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
// make an API request for your temporary credentials
$req_token = $oauth->getRequestToken("https://openapi.etsy.com/v2/oaut/request_token?scope=email_r%20listings_r%20listings_w", 'oob');
print $req_token['login_url']."'n";`
注意scope=email_r%20listings_r%20listings_w;
希望这能帮助
啊哈,这是答案。来自Etsy开发人员:
您的API尚未被批准完全访问API。我已经解决了这个问题,所以你现在应该可以使用这些方法了。
因此,请与该公司联系,并要求批准您的钥匙。