我在这里遇到了很大的两难选择,虽然我在Uber沙箱上使用重定向uri到http://localhost
进行了测试,但是下面的函数可以正常工作并返回访问令牌,并且我可以使用所有API调用就可以了,而没有错误
但是,当我尝试使用https将重定向URI更改为API时,以下功能将无法再使用,所有信息的接收方式与localhost一样,但是当执行CURL时,我得到
{"error":"invalid_request"}
下面的代码是我为此使用的功能:
function fetchUrl($url, $code)
{
$fields = array(
'client_id' => "MY_CLIENT_ID",
'client_secret' => "MY_CLIENT_SECRET",
'grant_type' => "authorization_code",
'code' => $code
);
$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_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//up to this point works for HTTPS redirect uri
$result = curl_exec($ch); //the second this runs, i get
//{"error":"invalid_request"}
curl_close($ch);
return $result;
}
上述功能:
$url
参数设置为https://login.uber.com/oauth/v2/token
并将$code
设置为在oauth进入低谷并返回必要的代码(该代码在100%的尝试中收到)后得到的值。
感谢您的帮助! 预先谢谢你!
答案 0 :(得分:0)
我在这里找到了一个解决方案,$code
仅应使用一次来生成access_token
和refresh_token
,以后将使用它们来刷新access_token
。>
我的错误是每次我使用uber中的方法时都尝试生成令牌,如果您按照此链接中的步骤操作,则不需要 https://developer.uber.com/docs/riders/guides/authentication/user-access-token 您可以确定它会正常工作!