Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用此JSON文件从服务器请求?_Php_Json_Get_Docusignapi - Fatal编程技术网

Php 如何使用此JSON文件从服务器请求?

Php 如何使用此JSON文件从服务器请求?,php,json,get,docusignapi,Php,Json,Get,Docusignapi,我有一个JSON文件,DocuSign在获取用户登录信息时给了我一个示例: { "uri" : "https://demo.docusign.net/restapi/v2/login_information?api_password=true&include_account_id_guid=true&login_settings=all" , "headers" : { "X-DocuSign-Authentication" : "{\Username\":\ .

我有一个JSON文件,DocuSign在获取用户登录信息时给了我一个示例:

{
  "uri" : "https://demo.docusign.net/restapi/v2/login_information?api_password=true&include_account_id_guid=true&login_settings=all" ,
  "headers" : {
    "X-DocuSign-Authentication" : "{\Username\":\ ... " // Truncated due to sensitive 
                                                        // information
  }
}
他们的API探索环境(使用敏感信息)然后访问服务器并返回另一个JSON文件,其中包含用户的所有登录信息


docusign如何使用
GET
方法实现这一点?我正在尝试使用PHP来完成这些请求。

我相信这只是他们页面上的一个例子,恰好以JSON格式表示数据,这可能是因为大多数web开发人员都很熟悉。如果您是通过另一个API接收json,您可以进行一些奇特的json解码,以编程方式将值插入到请求中,但这可能比大多数人需要做的更多

您正在通过GET发送URL中问号后的所有参数的有效负载

?api_password=true&include_account_id_guid=true&login_settings=all
您正在将身份验证凭据作为标头提供

<?php

$uri = 'https://demo.docusign.net/restapi/v2/login_information?api_password=true&include_account_id_guid=true&login_settings=all';
$headers = 'X-DocuSign-Authentication: {"Username":"","Password":"","IntegratorKey":""}';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$uri);

curl_setopt($ch, CURLOPT_HTTPHEADER, array($headers));

curl_exec ($ch);

curl_close ($ch);

你的问题到底是什么?也许再多解释一点会有帮助,我正试图通过
get
方法从DocuSign API获取信息,但我非常不确定如何获取信息。此外,上面的JSON文件是DocuSign在“获取登录信息”方法的“请求选项”下使用的示例。可以在这里找到探索环境:在哪里可以找到不同查询的所有不同常量,如“CURL\u URL”?似乎找不到有关用作“curl_setopt()”参数的文档。@Jodo1992它们都列在这里:很抱歉,我是一个有害生物,但您能再显示一个示例的代码吗?我很难通过POST理解“body”如何适合“gettoken”方法。没有参数
CURLOPT_BODY
。我尝试了
CURLOPT_COOKIE
,但也没有成功。有什么原因(在复制您的代码和应用我的信息时)我在终端中没有得到任何回报吗?嗯,在浏览器和终端中对我有效。但我当然没有账户,所以我收到了明显的错误信息。在他们的“试一试”页面上,你觉得它是什么样子?您将只看到响应正文中打印的内容,因此他们可能会在标题中而不是正文中向您发送返回,这将解释为什么返回为空白。要获取响应标题,请参见以下内容:
<?php

$uri = 'https://demo.docusign.net/restapi/v2/oauth2/token';
$headers = array(
  'Accept: application/json',
  'Content-Type: application/x-www-form-urlencoded',
  'Content-Length: 60'
);
$body = 'username=&password=&client_id=&grant_type=password&scope=api';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$uri);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

curl_exec ($ch);

curl_close ($ch);