如何通过 PHP 获得 API Curl 工作授权
How to get API Curl authorisation to work via PHP
我正在使用 dr chrono API 并尝试初始化第一步,即 authorisation
这是一个授权示例:
https://drchrono.com/o/authorize/?redirect_uri=REDIRECT_URI_ENCODED&response_type=code&client_id=CLIENT_ID_ENCODED&scope=SCOPES_ENCODED
这是我试过的:
1.) 我试过下面的第一个代码
<?php
echo "<a href='https://drchrono.com/o/authorize/?redirect_uri=https://example_site.com/return_page.php&response_type=code&client_id=myclient-id-goeshere&scope=BASE_SCOPE:[read|write]'>Authorize</a>";
?>
但是当页面重定向时它显示Invalid_scope的错误。下面是返回的错误link。
https://example_site.com/return_page.php?error=invalid_scope
2.) 使用卷曲
$ci = 'my-client-id-goes-here';
$ci_encode = urlencode($ci);
$uri = 'https://example_site.com/return_page.php';
$uri_encode = $uri;
$url = "https://drchrono.com/o/authorize/";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'response_type'=>'code',
'client_id'=>$ci_encode,
'redirect_uri'=>$uri_encode,
'scope'=>'BASE_SCOPE:[read|write]',
]));
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
使用上面的 curl 代码甚至完全重定向我。
我认为主要问题是范围设置不正确。我该如何解决这个问题?
更新
curl 的代码部分:
$ci = 'my-client-id';
$ci_encode = urlencode($ci);
$uri = 'https://example_site.com/return_page.php';
$uri_encode = $uri;
$url = "https://drchrono.com/o/authorize/?";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'response_type'=>'code',
'client_id'=>$ci,
'redirect_uri'=>$uri,
'scope'=>'patients:summary:read patients:summary:write calendar:read calendar:write clinical:read clinical:write'
]));
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
我会使用 patients:summary:read patients:summary:write calendar:read calendar:write clinical:read clinical:write
而不是 BASE_SCOPE:[read|write]
文档说您可以在用户、日历、患者、patients:summary、计费、临床和实验室中进行选择,并从这些值中构成一个范围。
我正在使用 dr chrono API 并尝试初始化第一步,即 authorisation
这是一个授权示例:
https://drchrono.com/o/authorize/?redirect_uri=REDIRECT_URI_ENCODED&response_type=code&client_id=CLIENT_ID_ENCODED&scope=SCOPES_ENCODED
这是我试过的:
1.) 我试过下面的第一个代码
<?php
echo "<a href='https://drchrono.com/o/authorize/?redirect_uri=https://example_site.com/return_page.php&response_type=code&client_id=myclient-id-goeshere&scope=BASE_SCOPE:[read|write]'>Authorize</a>";
?>
但是当页面重定向时它显示Invalid_scope的错误。下面是返回的错误link。
https://example_site.com/return_page.php?error=invalid_scope
2.) 使用卷曲
$ci = 'my-client-id-goes-here';
$ci_encode = urlencode($ci);
$uri = 'https://example_site.com/return_page.php';
$uri_encode = $uri;
$url = "https://drchrono.com/o/authorize/";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'response_type'=>'code',
'client_id'=>$ci_encode,
'redirect_uri'=>$uri_encode,
'scope'=>'BASE_SCOPE:[read|write]',
]));
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
使用上面的 curl 代码甚至完全重定向我。
我认为主要问题是范围设置不正确。我该如何解决这个问题?
更新
curl 的代码部分:
$ci = 'my-client-id';
$ci_encode = urlencode($ci);
$uri = 'https://example_site.com/return_page.php';
$uri_encode = $uri;
$url = "https://drchrono.com/o/authorize/?";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'response_type'=>'code',
'client_id'=>$ci,
'redirect_uri'=>$uri,
'scope'=>'patients:summary:read patients:summary:write calendar:read calendar:write clinical:read clinical:write'
]));
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
我会使用 patients:summary:read patients:summary:write calendar:read calendar:write clinical:read clinical:write
BASE_SCOPE:[read|write]
文档说您可以在用户、日历、患者、patients:summary、计费、临床和实验室中进行选择,并从这些值中构成一个范围。