所以,我遇到了问题,因为我没有 OAuth 1,所以要访问 ETSY API,我不得不努力。
最后我有这个:
我的函数 __construct() :
父::__construct();
$this->allowForUser();
$this->etsyDb = new EtsyordersModel;
$this->client = new Etsy([
'identifier' => getApp()->getConfig('identifier'),
'secret' => getApp()->getConfig('secret'),
'scope' => 'listings_r transactions_r',
'callback_uri' => 'http://*****-*****.loc/etsyapp/next',
'access_token' => getApp()->getConfig('access_token'),
'access_token_secret' => getApp()->getConfig('access_token_secret'),
]);
以下是我如何获取 url 以访问我的 JSON 的结果:
$key = rawurlencode($oauthtoken) . "&" . rawurlencode($tokensecret);
$method = "GET";
$baseurl = "https://openapi.etsy.com/v2/shops/24749672/receipts/";
$nonce = "1234";
$timenow = time();
$oauthversion = '1.0';
$paramstring = "oauth_consumer_key=" . $oauthconsumerkey . "&oauth_nonce=" . $nonce . "&oauth_signature_method=HMAC-SHA1" . "&oauth_timestamp=" . $timenow . "&oauth_token=" . $clientsecret . "&oauth_version=" . $oauthversion;
//
// Signature GET to retrieve signature OAuth
$encodeurl = $method . "&" . rawurlencode($baseurl) . "&" . rawurlencode($paramstring);
$signature = hash_hmac( 'sha1', $encodeurl, $key, TRUE );
$signature = base64_encode( $signature );
// url JSON shop ETSY
$curlurl = $baseurl . "?" . $paramstring . "&oauth_signature=" . $signature;
// get JSON content in $orders
$orders = file_get_contents($curlurl);
所以我得到了我的 JSON :
我得到了 90++ 个项目,但由于分页,它只显示了 25 个项目。
我试图添加active?limit=100&offset=0
到我的 $baseurl (在它的末尾,作为签名计算的参数),但它说oauth_problem=signature_invalid&
. 我试着把它放在上面$paramstring
,但结果相同。如何显示所有结果,或者如何访问分页的第 2、3 等页?
我使用的是 PHP 7.4、XAMPP(最后一个版本之一),我没有 OAuth 1,所以我使用了包 Y0lk\OAuth1 和 thephpleague\oauth1-client 的组合。
感谢您的时间。