方案
在远程API文档
上使用API测试的一个网址:
http://ops.epo.org/3.2/rest-services/published-data/publication/docdb/EP1000000/biblio
代码
use GuzzleHttp\Client;
private function connectEPO
{
$base_uri = 'https://ops.epo.org/3.2/';
$urlAccessToken' = 'https://ops.epo.org/3.2/auth/accesstoken',
$consumerKey = 'mysecretkey';
$consumerSecretKey = 'myconsumersecretkey';
$client = new Client([
'base_uri' => 'https://ops.epo.org/3.2/'
]);
$response = $client->request('POST', 'auth/accesstoken', [
'auth' => [$consumerKey,$consumerSecretKey]
]);
dd($response);
}
错误
[GuzzleHttp\Exception\ClientException]
Client error: `POST https://ops.epo.org/3.2/auth/accesstoken` resulted in a `400 Bad Request` response:
<error><code>400</code><message>Required param : grant_type</message>
</error>
也可以尝试
$client = new Client([
'base_uri' => 'https://ops.epo.org/3.2/'
]);
$request = $client->post('auth/accesstoken', null, array(
'consumerKey' => $consumerKey',
'consumerSecretKey' => $consumerSecretKey,
'grant_type' => 'client_credentials'
));
dd($request);
错误
[GuzzleHttp\Exception\ClientException]
Client error: `POST https://ops.epo.org/3.2/auth/accesstoken` resulted in a `401 Unauthorized` response:
<error><code>401</code><message>Client identifier is required</message>
</error>
尝试几种选择,但我理解或看不到Guzzle手册的正确方法。