如何解决Etsy Api PHP 认证请求
目前我想制作一个带有按钮的页面,该按钮将检索我在 ETSY 上的所有商店订单的列表。
我找到了完美的包裹 https://github.com/inakiabt/etsy-php 有了它,一旦我检索到访问令牌,我只需要做这样的事情
$api->findAllShopReceipts(array('params' => array('shop_id' => '__SELF__')))
但是我的 Xampp(我使用的是 win 10 x64)没有 OAuth (PHPinfo()
) 所以我不得不使用这个包:https://github.com/Y0lk/oauth1-etsy
这是我的代码:
类 EtsyController 扩展了 MasterController { const VIEWS = 'etsyapp';
private $client;
/**
* Constructeur
*/
public function __construct()
{
parent::__construct();
$this->client = new Etsy([
'identifier' => '***********************','secret' => '**********','scope' => 'listings_r transactions_r','callback_uri' => 'http://**********.loc/etsyapp/next','access_token' => $_SESSION['access_token'],'access_token_secret' => $_SESSION['access_token_secret'],]);
}
/**
* TEST AVEC PACKAGE Y0lk
*/
public function EtsyConnect()
{
// On envoi une requête à l'API avec notre consumer & secrey key,et elle nous renvoi nos identifiants temporaires
$tempCred = $this->client->getTemporaryCredentials();
// On store nos identifiants dans la Session
$_SESSION['temporary_credentials'] = serialize($tempCred);
$tmpSecret = $tempCred->getSecret();
$tmpId = $tempCred->getIdentifier();
// Avec nos infos on creer un lien vers une page d'autoriation de liaison de compte Etsy avec notre API
$redirect_url = $this->client->getAuthorizationUrl($tempCred);
return $this->render(self::VIEWS.'/home',[
'redirect_url' => $redirect_url,]);
}
/**
* TEST AVEC PACKAGE Y0lk
*/
public function EtsyNext()
{
if (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier'])) {
// Retrieve the temporary credentials we saved before
$tempCred = unserialize($_SESSION['temporary_credentials']);
// We will Now retrieve token credentials from the server
$tokenCredentials = $this->client->getTokenCredentials($tempCred,$_GET['oauth_token'],$_GET['oauth_verifier']);
// Je stock mes token en BDD (ou en SESSION,ou ailleurs...)
$_SESSION['all_access_token'] = $tokenCredentials;
$_SESSION['access_token'] = $tokenCredentials->getIdentifier();
$_SESSION['access_token_secret'] = $tokenCredentials->getSecret();
}
return $this->render(self::VIEWS.'/next',[]);
}
}
我使用 EtsyConnect 来获取临时凭证,这允许我转到 etsy 登录/允许访问页面,并且在确认后,使用 URL 中的访问令牌回调我的 uri,在 EtsyNext 中我获得这些访问令牌,并存储它们在数据库中(为了我的测试,我只是将它们放在 SESSION 中)。
现在我的 $this->client = new Etsy
拥有所有令牌,这意味着我不必再次进入登录页面。
但是从这里开始,我如何执行此请求:
我知道使用 inakiabt 包,我所要做的就是这样:
$api = new EtsyApi($this->client);
$api->findAllShopReceipts(array('params' => array('shop_id' => '__SELF__')));
但没有它我真的不知道。我什至试图用 curl 调用 url 但正常答案:This method requires authentication.
有人可以帮我做这个经过身份验证的请求吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。