我正在使用PHP与UBER API的集成。我在OAuth流方面遇到了问题。在尝试将访问代码交换为访问令牌后,我得到了{"error": "invalid_grant"}。
它工作得很好,但今天它就停止工作了。调试它时,我看到优步提供的访问代码格式是:IPjvWABDxk00000BxQQwJksP2I50qD#_,我认为最后的"#_“给我带来了问题,因为php $_GET无法读取完整的字符串(来自IP..到...#_)。我的代码:
$uber_access_code = $_GET["code"];
$fields_string = '';
$fields = array(
'client_secret' => $uber_client_secret,
'client_id' => $uber_client_id,
'grant_type' => 'authorization_code',
'code' => $uber_access_code,
'redirect_uri' => $uber_redirect_uri,
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, "https://login.uber.com/oauth/v2/token");
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);问:如何从PHP中读取完整的字符串参数?$_GET在我这一端修剪了"#_“,但我需要整个字符串。
发布于 2018-03-03 10:24:32
当我在我的本地机器上测试它时,我可以复制你的问题,但我不认为这是一个php问题。看起来像是浏览器的问题。因为当我检查apache访问日志时,我可以看到它正在发送如下请求。
"GET /result.php?code=IPjvWABDxk00000BxQQwJksP2I50qD HTTP/1.1" 200 148如果您是创建此GET请求URL的人,则可以执行以下操作。
例如,form.php
<html>
<body>
<?php
$link = base64_encode('IPjvWABDxk00000BxQQwJksP2I50qD#_');
?>
<a href="result.php?code=<?php echo $link;?>">link</a>
</body>
</html>和result.php
<?php
var_dump(base64_decode($_GET['code']));
?>你会得到有效的结果,比如
string 'IPjvWABDxk00000BxQQwJksP2I50qD#_' (length=32)https://stackoverflow.com/questions/49079878
复制相似问题