Pau*_*nmi 2 request getresponse oauth-2.0 guzzle guzzle6
我正在尝试使用 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);
Run Code Online (Sandbox Code Playgroud)
我还尝试在标头中传递 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); `
Run Code Online (Sandbox Code Playgroud)
然而,两种方法中的 getParsedResponse 函数都会返回以下内容:
League \ OAuth2 \ Client \ Provider \ Exception \ IdentityProviderException (400) UnsupportedContentTypeheader.
Run Code Online (Sandbox Code Playgroud)
小智 5
我知道已经晚了,但请尝试以下代码:
$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 );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2462 次 |
| 最近记录: |