php - 如何获得 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);
解决方案
而不是BASE_SCOPE:[read|write]
我会使用patients:summary:read patients:summary:write calendar:read calendar:write clinical:read clinical:write
文档说您可以在用户、日历、患者、患者:摘要、计费、临床和实验室中进行选择,并根据这些值组成一个范围。
推荐阅读
- linux - 在 Linux 上指定 odbc 驱动程序管理器
- sql-server - 在 Access 查询中定义参数的目的
- c++ - 静态类成员不是与this指针没有关联吗?
- maven - 从 pom 中排除测试文件夹不起作用
- android - Android 或 iOS 支持修改屏幕上的文字?
- c - 程序在等待退出时超时
- javascript - 在 vuejs 中放置一个事件处理程序?
- javascript - js 文件没有正确导入 js 模块,即使在 html 中插入了 type="module"
- python - 哪个更快?设置比较还是计数器比较?为什么
- c# - 在标签页内的列表中使字符串可点击