php - 我收到一个 POST 请求的奇怪参数错误
问题描述
所以这是我在尝试向 streamlabs api 发出 POST 请求时遇到的错误。我已经把 pastebin 放到了下面的上帝那里。
我很可能是那么愚蠢。谢谢
编辑:即使使用 $code = $_GET['code']; 它仍然返回相同的错误。我不确定为什么。可能是接收器的api有问题吗?我是 php 和 POST / GET 调用的新手。通常我通过 Ajax 制作它们,但它总是返回一个 CORS 错误,因为它们强制使用 php 以确保安全。它仅供个人使用,不会被其他任何人使用。
解决方案:我不确定如何有效地使用堆栈溢出,所以我提前道歉,但解决方案在 Drew010 的评论中!
编码:
<?php
$code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_URL);
$client_id = 'Removed For Security'; // Your client id
$client_secret = 'Removed For Security'; // Your secret
$redirect_uri = "http://simpservers.co.uk/supporters/"; // Your redirect uri
$url = 'https://streamlabs.com/api/v1.0/token';
# Our new data
$data = array('grant_type' => 'authorization_code', 'client_id' => $client_id, 'client_secret' => $client_secret, 'redirect_uri' => $redirect_uri, 'code' => strval($code));
# Create a connection
$url = 'https://streamlabs.com/api/v1.0/token';
//initialize cURL
$handle = curl_init($url);
//post values
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
//set to return the response
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
//execute
$response = (curl_exec( $handle ));
print_r($data);
echo $response;
数据:
(
[grant_type] => authorization_code
[client_id] => Removed For Security
[client_secret] => Removed For Security
[redirect_uri] => http://simpservers.co.uk/supporters/
[code] => 4M8WUq97OzeBgL3O41tmVEb4dY9HAy3zdeRQWFFg
)
The response:
{
"error":"invalid_request",
"error_description":"The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"code\" parameter."
}
解决方案
推荐阅读
- python - 如何确定 Tensorflow 模型需要多少 GPU 内存?
- java - 基于微调器选择显示 ListView
- go - Golang在超时Goroutine上的间歇性行为
- reactjs - 如何在没有多个构建的情况下将 React 应用程序部署到多个环境?
- javascript - javascript点击功能在ios中无法正常工作
- git - .gitconfig“错误的配置行”由于别名
- vue.js - 如何在 localhost 中使用 HTTPS 运行 NUXT(npm run dev)?
- c# - 如何通过文本文件在控制台上显示学生的姓名和平均成绩?
- python-3.x - 将张量分成两组的最快方法,对于每组,随机将一个分配给 0,另一个分配给 1
- swift - '不能用'UIImagePickerController.Infokey'类型的索引为'[NSObject:AnyObject]'类型的值下标