2016-04-28 113 views
7

我正在使用WooCommerce API,但我遇到了請求問題。WooCommerce API返回404未找到

有時API請求返回404或重定向到「我的帳戶」。

API請求,例如:

https://example.com/index.php/wc-api/v3/products?consumer_key=ck_XXXXXXXXX&consumer_secret=cs_XXXXXXXXX`. 

漂亮的鏈接已啓用。

這是我.htacess

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 

任何想法?

+0

您是否嘗試過所有這些:http://stackoverflow.com/questions/22429771/woocommerce-rest-api-returns-404-未找到 https://github.com/kloon/WooCommerce-REST-API-Client-Library/issues/11 http://stackoverflow.com/questions/22710078/woocommerce-rest-api-404-error http://woopos.com.au/faq/getting-404-error-page-found/ –

+0

是的,我嘗試了一切。沒有任何工作,我已啓用永久鏈接 – user1269586

+0

URI中有一個空格,我希望在這個問題中只有一個錯誤,而不是在你的代碼中:'consumer_secret = cs_XXXXXXXXX' – tillz

回答

1

請從這裏下載SDK:https://packagist.org/packages/automattic/woocommerce 並從這裏獲取指導:https://woothemes.github.io/woocommerce-rest-api-docs/。 ,打造API憑證形式的WordPress管理結束woocommerce>設置>添加新鍵

$client = 'ck_63aade4xxxxxxxxxxxxxxx'; //put client key 
$secret = 'cs_673d7cdxxxxxxxxxxxxxxx'; //put secret key 


require __DIR__ . '/restapi/vendor/autoload.php'; //give your sdk autoload.php path 


use Automattic\WooCommerce\Client; 

$woocommerce = new Client(
    'http://localhost:8888/woocommerce/', //site url 
    $client, 
    $secret, // Your consumer secret 
    [ 
     'version' => 'v3' // WooCommerce API version 
    ] 
); 

print_r($woocommerce->get(''));