dongye9182 2019-02-19 09:26
浏览 185
已采纳

如何使用refresh_token刷新uber的access_token

i have a problem, when i generate the first oauth response via uber api, i get all the information needed(access_token, refresh_token)

But when i wish to refresh the access_token for a specific user, i get invalid_grant(i know that this means the refresh token has expired, but i generate the codes and at first try it fails even if the codes are still valid)

this is the code i use for refreshing the token, can someone please explain why it is failing to give me a new code?

function refreshToken()
{
    $url = 'https://login.uber.com/oauth/v2/token';
    $fields = array(
        'client_id' => MY_CLIENT_ID,
        'client_secret' => MY_CLIENT_SECRET,
        'grant_type' => "refresh_token",
        'refresh_token' => MY_REFRESH_TOKEN
    );

    $fields_string = '';
    foreach ($fields as $key => $value) {
        $fields_string .= $key . '=' . $value . '&';
    }

    $fields_string = rtrim($fields_string, '&');

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_VERBOSE, true);

    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

I have the codes stored in the database, grab them and try to use them from there, the auth-code works fine after i oauth, but i need to be able to refresh the access token in order to query the UBER api for the receipt ready post on my webhook, if the token is expired i can't access the call with the current auth token i have(bearer token)

this is the response i get every time:

[error] => invalid_grant
  • 写回答

1条回答 默认 最新

  • dqenv99518 2019-02-19 09:43
    关注

    I was storing the refresh token wrong in the database: the length was higher than the one i was storing under. eg: i was storing varchar(100) , i set it to varchar(255) now it works like a wonder.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配