Return HTTPS 响应正文中的 JSON 对象
Return a JSON object in the body of a HTTPS response
我有一个 OAUTH 2.0 服务器,我已经使用 PHP
成功地将它实现到最后一级
参考 Link : https://developers.google.com/actions/identity/oauth2-code-flow
但是,我现在正处于最后一步
---> Return HTTPS 响应正文中的以下 JSON 对象
{
token_type: "bearer",
access_token: "ACCESS_TOKEN",
refresh_token: "REFRESH_TOKEN",
expires_in: SECONDS_TO_EXPIRATION
}
我做了以下事情
$json = array(
'token_type:' => "bearer",
'access_token:' => $ACCESS_TOKEN,
'refresh_token:' => $REFRESH_TOKEN,
'expires_in:' => '3600'
);
$jsonstring = json_encode($json);
echo $jsonstring;
die();
其中$ACCESS_TOKEN
和$REFRESH_TOKEN
两个变量包含了必要的信息。
我的问题是我如何 return 'JSON object in the body of the HTTPS response: '?
如果有人能帮我解决这个问题,那将意义重大
提前致谢!
请访问这个网站,看看你可能会明白我想做什么:)
https://developers.google.com/actions/identity/oauth2-code-flow
你的大部分操作似乎都是正确的。将 JSON 作为 body 发送需要两个步骤。
首先,您必须设置 content-type header 以指示 body 是 JSON。您必须在输出任何其他数据(包括空行)之前执行此操作。在页面上的 PHP header 之后添加它可能是确保没有其他内容生成它的好习惯。 header 的完成方式类似于
<?php
header("Content-type:application/json");
您的其余代码看起来是正确的。发送 "JSON Object" 意味着发送特定格式的数据文本表示。该格式是通过 json_encode().
完成的
$json = array(
'token_type:' => "bearer",
'access_token:' => $ACCESS_TOKEN,
'refresh_token:' => $REFRESH_TOKEN,
'expires_in:' => '3600'
);
$jsonstring = json_encode($json);
echo $jsonstring;
我有一个 OAUTH 2.0 服务器,我已经使用 PHP
参考 Link : https://developers.google.com/actions/identity/oauth2-code-flow
但是,我现在正处于最后一步
---> Return HTTPS 响应正文中的以下 JSON 对象
{
token_type: "bearer",
access_token: "ACCESS_TOKEN",
refresh_token: "REFRESH_TOKEN",
expires_in: SECONDS_TO_EXPIRATION
}
我做了以下事情
$json = array(
'token_type:' => "bearer",
'access_token:' => $ACCESS_TOKEN,
'refresh_token:' => $REFRESH_TOKEN,
'expires_in:' => '3600'
);
$jsonstring = json_encode($json);
echo $jsonstring;
die();
其中$ACCESS_TOKEN
和$REFRESH_TOKEN
两个变量包含了必要的信息。
我的问题是我如何 return 'JSON object in the body of the HTTPS response: '?
如果有人能帮我解决这个问题,那将意义重大
提前致谢!
请访问这个网站,看看你可能会明白我想做什么:)
https://developers.google.com/actions/identity/oauth2-code-flow
你的大部分操作似乎都是正确的。将 JSON 作为 body 发送需要两个步骤。
首先,您必须设置 content-type header 以指示 body 是 JSON。您必须在输出任何其他数据(包括空行)之前执行此操作。在页面上的 PHP header 之后添加它可能是确保没有其他内容生成它的好习惯。 header 的完成方式类似于
<?php
header("Content-type:application/json");
您的其余代码看起来是正确的。发送 "JSON Object" 意味着发送特定格式的数据文本表示。该格式是通过 json_encode().
完成的$json = array(
'token_type:' => "bearer",
'access_token:' => $ACCESS_TOKEN,
'refresh_token:' => $REFRESH_TOKEN,
'expires_in:' => '3600'
);
$jsonstring = json_encode($json);
echo $jsonstring;