Woocommerce Rest API:错误:请求中发生错误,当时无法发送消费者数据

Posted

技术标签:

【中文标题】Woocommerce Rest API:错误:请求中发生错误,当时无法发送消费者数据【英文标题】:Woocommerce Rest API: Error: An error occurred in the request and at the time were unable to send the consumer data 【发布时间】:2019-04-04 06:36:15 【问题描述】:

我正在使用 Woo-commerce 官方 rest sdk 在我的 Laravel 5.6 站点中集成 Woo-commerce API。我使用身份验证端点 URL 创建了一个链接。here 提到了这一点。

当用户点击链接时,它会将用户带到 Woo-commerce 身份验证页面,用户登录并批准请求。

批准请求后,我应该返回链接中提到的 url。相反,它向我显示以下错误。

错误:请求发生错误,当时无法发送消费者数据。

这是我的代码。 `$store_url = 'YourStoreUrl';

    $endpoint = '/wc-auth/v1/authorize';
    $params = [
        'app_name' => 'YourApplicationName',
        'scope' => 'read_write',
        'user_id' => 'yourUserId',
        'return_url' => 'YourStoreUrl/callbackurl',
        'callback_url' => 'YourStoreUrl/returncallback'
    ];
    $query_string = http_build_query( $params );

    $url =  $store_url . $endpoint . '?' . $query_string;`

【问题讨论】:

你应该把你当前的代码放在这里 抱歉忘记了我的链接生成添加了。我关注 woocommerce 文档。 【参考方案1】:

对于可能遇到同样问题的未来用户,请确保您的callback_url 正确无误。该错误主要是由于callback_url

就我而言,我最初有这段python 代码:

store_url = 'http://localhost/wordpress'
endpoint = '/wc-auth/v1/authorize'
params = 
    "app_name": "My app",
    "scope": "read_write",
    "user_id": 123,
    "return_url": "http://localhost/wordpress/",
    "callback_url": "https://f46c7c857579.ngrok.io",

query_string = urlencode(params)

return "%s%s?%s" % (store_url, endpoint, query_string)

但是我的callback_url 错了。当我输入正确的callback_url 时,错误消失了。 callback_url": "https://f46c7c857579.ngrok.io/return"

另外,请确保您的 callback_url 具有 POST HTTP METHOD

【讨论】:

以上是关于Woocommerce Rest API:错误:请求中发生错误,当时无法发送消费者数据的主要内容,如果未能解决你的问题,请参考以下文章

错误 Woocommerce REST API 扩展订单“line_items”响应

登录时 WooCommerce REST API 身份验证失败

使用Javascript的WooCommerce Rest API Oauth

WooCommerce REST API 无效的 JSON

WooCommerce REST API - 按修改日期过滤订单

woocommerce通过rest api验证用户名和密码