php - 无法使用有效访问 key 从 Uber API 获取 token

标签 php curl oauth-2.0 uber-api

过去几天我一直在尝试将我的应用程序与 uber 集成,但由于某些原因,在 oauth2 身份验证期间,我无法让 uber 给我一个有效的 token 。我可以获得访问代码,但是使用curl 时,无论我如何安排脚本,我似乎都无法获得访问 token 。这是我所拥有的:

<?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;

?>

我已经仔细检查了我的 secret 和 ID,两者都是正确的。我可以看到每次我要获取访问代码时它都是独一无二的,我可以看到它在我重定向到的授权页面上回显,但无论我如何不断收到响应:

{"error": "access_denied"}

最佳答案

发生此错误的原因是:

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.

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 - 无法使用有效访问 key 从 Uber API 获取 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30429399/

相关文章:

php - 如何在 Laravel Passport 中启用客户端凭据授予类型

objective-c - ios gtm-oauth 没有键盘

c# - 为我的 API 实现 OAuth 2.0 身份验证

php - pgsql - 如何仅获取存储过程中非空值的总和

php - 24小时内阻止同一IP执行某项操作

c# - 使用 asp.net mvc 应用程序的 HttpClient post 请求 WebApi

javascript - Node.js:提交表单时接收空正文

PHP CURL 超时,不管超时是什么

php - 使用(客户端)javascript 直接连接到 Redis?

php - 如何使用 php 降低图像质量/图像大小,我们尝试过但无法解决?