Oauth 2.0 向HPLeague/oauth2客户端发出POST请求

Oauth 2.0 向HPLeague/oauth2客户端发出POST请求,oauth-2.0,request,guzzle6,guzzlehttp,getresponse,Oauth 2.0,Request,Guzzle6,Guzzlehttp,Getresponse,我试图使用HPLeague/oauth2客户端和adespresso/oauth2 GETResponse作为提供程序向GETResponse API()发出POST请求,如下所示: $data = [ 'email' => $email, 'campaign' => [ 'campaignId' => $campId ] ]; $request

我试图使用HPLeague/oauth2客户端和adespresso/oauth2 GETResponse作为提供程序向GETResponse API()发出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);
我还尝试在头文件中传入application/json的content-type值,但都没有用

$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 );

使用
json\u encode()
传递POST数据对我不起作用,我尝试了不同的解决方案,但这是唯一对我有效的解决方案

$postData = [
    'date' => $date,
    'service_ids' => $serviceId,
];
$options = [
    'body' => http_build_query($postData),
    'headers' => [
        'Content-Type' => 'application/x-www-form-urlencoded',
    ],
];

$request = $this->provider->getAuthenticatedRequest("POST", $requestUrl, $token, $options);
$response = $this->provider->getParsedResponse($request);

这对我来说也适用于Bitly API。如果您正在进行Bitly调试,有一件事是必需的:
group\u guid
,尽管文档中没有这样说。