You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在SellingPartnerApi::seller()中使用自定义Guzzle客户端遇认证错误

解决Saloon\Http\Senders\GuzzleSender::$client未初始化错误

解决方案

你需要用Saloon的GuzzleSender包装自定义的GuzzleHttp\Client实例,再传入authenticationClient参数,而非直接传入GuzzleClient本身。

步骤代码

  1. 引入Saloon的GuzzleSender类:
use Saloon\Http\Senders\GuzzleSender;
  1. 创建自定义GuzzleClient并包装:
// 实例化带代理配置的GuzzleClient
$httpClient = new \GuzzleHttp\Client([
    'proxy' => 'http://username:password@proxy_host:port',
    'timeout' => 30,
    'connect_timeout' => 30,
]);

// 用GuzzleSender包装自定义客户端
$authSender = new GuzzleSender($httpClient);

// 初始化SellingPartnerApi
$api = SellingPartnerApi::seller(
    clientId: $credentials->api_client_id,
    clientSecret: $credentials->api_client_secret,
    refreshToken: $credentials->refresh_token,
    endpoint: Endpoint::NA,
    authenticationClient: $authSender
);
  1. 发起请求:
$response = $api->sellersV1()->getMarketplaceParticipations();

原因说明

jlevers/selling-partner-api SDK基于Saloon框架构建,authenticationClient参数的实际类型要求是Saloon的Sender接口实现(如GuzzleSender),而非直接的GuzzleHttp\Client。直接传入GuzzleClient会导致Saloon内部无法正确初始化GuzzleSender的$client属性,从而触发Typed property Saloon\Http\Senders\GuzzleSender::$client must not be accessed before initialization错误。

即使是无额外配置的纯净GuzzleClient,也必须通过GuzzleSender包装后才能符合参数类型要求,文档描述可能存在歧义导致误解。

内容的提问来源于stack exchange,提问作者Serhii Bondarenko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 17:02:51