dongtanliefang8765 2018-10-23 19:39
浏览 157

File_Get_Contents()有效,但automattic / woocommerce客户端没有。 [woocommerce_rest_cannot_view]

I am able to pull orders, from my shop, with a simple file_get_contents(), but I cant get the automattic/woocommerce php library to work. And by 'work' I mean that it does connect and try to pull the orders, but the store not allowing it. (error: [woocommerce_rest_cannot_view] ). I have been successful pulling orders, with the library, on a different woo install.

Here's my code: (i've played with the options a bit, no luck)

function d($var){var_dump($var);}

$woocommerce = new Client(
    "https://{$domain}.com/", 
    $ckey, 
    $csec, 
    array( 'wp_api' => true
         ,'version' => 'wc/v2' 
         ,'verify_ssl' => false
         ,'queryStringAuth' => false
        )
);

try {
   $results = $woocommerce->get('orders');
} catch (HttpClientException $e) {
   d( $e->getMessage() );
        // Error: Sorry, you cannot list resources. [woocommerce_rest_cannot_view]
   d(  $e->getRequest()->getUrl() );
        // https://example.com/wp-json/wc/v2/orders 
   d(  $e->getRequest()->getparameters() ); 
       // empty array 
}


$res = json_decode(file_get_contents("https://{$domain}.com/wp-json/wc/v2/orders?consumer_key={$ckey}&consumer_secret={$csec}&per_page=99"));
d($res );
// works, full list of orders.
  • 写回答

1条回答 默认 最新

  • dongyan3018 2018-10-24 07:09
    关注

    After a short look in the documentation you posted in your comments: read the docs! Especially the part about $lastRequest->getBody()

    You only do the get request, but dont read the reaponse body.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料