首页 > 解决方案 > 如何获得 API Curl 授权以通过 PHP 工作

问题描述

我正在使用dr chrono API并尝试初始化授权的第一步

API文档在这里

这是一个授权示例:

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错误。以下是返回的错误链接。

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

标签: phpcurlphp-curl

解决方案


而不是BASE_SCOPE:[read|write]我会使用patients:summary:read patients:summary:write calendar:read calendar:write clinical:read clinical:write

文档说您可以在用户、日历、患者、患者:摘要、计费、临床和实验室中进行选择,并根据这些值组成一个范围。


推荐阅读