无法使用有效访问密钥从Uber API获取令牌 [英] Cannot Get Token from Uber API with Valid Access Key

查看:199
本文介绍了无法使用有效访问密钥从Uber API获取令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been trying for the past few days to integrate my app with uber, but for some reason during the oauth2 authentication I can't get uber to give me a valid token. I can get an access code but when using curl, I can't seem to get an access token, no matter how I arrange my script. Here's what I have:

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

?>

我已经重新检查了我的秘密和ID,两者都是正确的。我可以看到每次我要获取访问代码它是一个独特的,我可以看到它在我重定向到的授权页面,但无论我一直得到的答复:

I've double checked my secret and id, both are correct. I can see each time I'm going to get the access code it's something unique, I can see it echoed out on the authorization page I'm redirecting to, but no matter what I keep getting the response as:

{"error": "access_denied"}


推荐答案

发生此错误是因为:

  • You are not sending a redirect_uri parameter to the GET https://login.uber.com/oauth/v2/authorize endpoint and you also didn't set a redirect URI in Uber Developers Dashboard for the client application you are using in the API requests.

重定向网址

这些网址将在OAuth身份验证期间使用。

如果您的请求中未包含重定向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.




  • 您发送的重定向网址无效(URI的基址与Uber Developers Dashboard中设置的重定向网址不同),

    作为 GET https://login.uber.com的文档/ oauth / v2 / authorize 说:

    • You are sending an invalid redirect URL (the base of the URI is not the same as the redirect URL set in Uber Developers Dashboard),
      as the documentation for the GET https://login.uber.com/oauth/v2/authorize says:

    • redirect_uri(可选)

      资源所有者在
      授权之后将重定向回的URI。

      URI的基址必须与您在应用程序注册期间使用的redirect_uri匹配。

      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.

      这篇关于无法使用有效访问密钥从Uber API获取令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆