php-无法使用有效访问密钥从Uber API获取令牌
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php-无法使用有效访问密钥从Uber API获取令牌,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1711字,纯文字阅读大概需要3分钟。
内容图文
![php-无法使用有效访问密钥从Uber API获取令牌](/upload/InfoBanner/zyjiaocheng/692/10d6b973a0ae48e0875f16489130e45a.jpg)
我过去几天一直在尝试将我的应用程序与uber集成,但是由于某种原因,在oauth2身份验证期间,我无法得到uber给我一个有效的令牌.我可以获得访问代码,但是使用curl时,无论我如何安排脚本,我似乎都无法获得访问令牌.这是我所拥有的:
<?php
echo $_GET['code']."<br>";
$token = curl_init();
$param = array(
'client_secret' => 'MY_SECRET',
'client_id' => 'MY_ID',
'grant_type' => 'authorization_code',
'code' => "{$_GET['code']}"
);
$postData = '';
foreach($param as $k => $v)
{
$postData .= $k . '='.urlencode($v).'&';
}
$postData = rtrim($postData, '&');
curl_setopt($token, CURLOPT_URL, 'https://login.uber.com/oauth/token');
curl_setopt($token, CURLOPT_HEADER, true);
curl_setopt($token, CURLOPT_RETURNTRANSFER, true);
curl_setopt($token, CURLOPT_POST, true);
curl_setopt($token, CURLOPT_POSTFIELDS, $postData);
$returned_token = curl_exec($token);
curl_close($token);
echo $returned_token;
?>
我已经仔细检查了我的秘密和身份证,两者都是正确的.我每次看到访问代码时都会看到它是唯一的东西,我可以看到它在重定向到的授权页面上回显了,但是无论我得到的响应如何:
{"error": "access_denied"}
解决方法:
发生此错误的原因是:
>您没有将redirect_uri参数发送到GET https://login.uber.com/oauth/v2/authorize端点,也没有在Uber Developers Dashboard中为API请求中使用的客户端应用程序设置重定向URI.
Redirect URL
These URLs will be used during OAuth Authentication.
If no redirect URI is included with your request, the default URL will be
used.
>您发送的重定向URL无效(URI的基础与Uber开发人员信息中心中设置的重定向URL不同),
如GET https://login.uber.com/oauth/v2/authorize的文档所述:
redirect_uri (optional)
The URI we will redirect back to after an
authorization by the resource owner.
The base of the URI must match the redirect_uri used during the registration of your application.
内容总结
以上是互联网集市为您收集整理的php-无法使用有效访问密钥从Uber API获取令牌全部内容,希望文章能够帮你解决php-无法使用有效访问密钥从Uber API获取令牌所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。