gpt4 book ai didi

oauth-2.0 - 使用 phpleague/oauth2-client 发出 POST 请求

转载 作者:行者123 更新时间:2023-12-02 14:56:23 24 4
gpt4 key购买 nike

我正在尝试使用 phpleague/oauth2-client 和 adespresso/oauth2-getresponse 作为提供者向 GETResponse API(https://apidocs.getresponse.com/v3/case-study/adding-contacts)发出 POST 请求,如下所示:

  $data = [
'email' => $email,
'campaign' => [
'campaignId' => $campId
]
];
$request = $this->provider->getAuthenticatedRequest(
'POST',
'https://api.getresponse.com/v3/contacts',
$this->getMyAccessToken(),
$data
);
$response = $this->provider->getParsedResponse($request);

我也尝试过在 header 中传入 application/json 的内容类型值,但都无济于事。

$data = [ 'email' => $email, 'campaign' => [ 'campaignId' => $campId ] ];

`$options['body'] = json_encode($data);
$options['headers']['Content-Type'] = 'application/json';
$options['headers']['access_token'] = $this->getMyAccessToken();
$request = $this->provider->getAuthenticatedRequest(
'POST',
'https://api.getresponse.com/v3/contacts',
$options
);
$response = $this->provider->getParsedResponse($request); `

然而,两种方法中的 getParsedResponse 函数都会返回以下内容:

League \ OAuth2 \ Client \ Provider \ Exception \ IdentityProviderException (400) UnsupportedContentTypeheader.

最佳答案

我知道已经晚了,但试试这个代码:

$data = array(
'email' => $email,
'campaign' => array([
'campaignId' => $campId
])
);

$options['body'] = json_encode( $data );
$options['headers']['Content-Type'] = 'application/json';
$options['headers']['Accept'] = 'application/json';
$request = $this->provider->getAuthenticatedRequest( 'POST', 'https://api.getresponse.com/v3/contacts', $this->getMyAccessToken(), $options );
$response = $this->provider->getParsedResponse( $request );

关于oauth-2.0 - 使用 phpleague/oauth2-client 发出 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52718933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com