php curl无法与Dropbox Oauth一起工作,返回“无效请求”
Dropbox文档说要进行身份验证您必须执行以下操作:
curl https://api.dropbox.com/oauth2/token \
-d code=<AUTHORIZATION_CODE> \
-d grant_type=authorization_code \
-d redirect_uri=<REDIRECT_URI> \
-u <APP_KEY>:<APP_SECRET>
这是我对PHP的尝试,但是在错误之后返回dropbox 无效请求 - 请求参数与任何支持的授权流不匹配
$url = "https://api.dropbox.com/oauth2/token";
$redirect_uri = 'https://www.mywebsite.com/oauth_dropbox';
$postfields = array(
'code' => $_GET['code'],
'grant_type' => 'authorization_code',
'redirect_uri' => $redirect_uri
);
$auth = "$app_key:$app_secret";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postfields));
curl_setopt($curl, CURLOPT_USERPWD, $auth);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
$responseObj = json_decode($json_response);
我如何求解?
Dropbox documentation says to authenticate you have to do the following:
curl https://api.dropbox.com/oauth2/token \
-d code=<AUTHORIZATION_CODE> \
-d grant_type=authorization_code \
-d redirect_uri=<REDIRECT_URI> \
-u <APP_KEY>:<APP_SECRET>
Here is my attempt with PHP but dropbox returns following error invalid request - The request parameters do not match any of the supported authorization flows
$url = "https://api.dropbox.com/oauth2/token";
$redirect_uri = 'https://www.mywebsite.com/oauth_dropbox';
$postfields = array(
'code' => $_GET['code'],
'grant_type' => 'authorization_code',
'redirect_uri' => $redirect_uri
);
$auth = "$app_key:$app_secret";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postfields));
curl_setopt($curl, CURLOPT_USERPWD, $auth);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
$responseObj = json_decode($json_response);
How do i solve?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您明确设置基本授权,那就可以做到这一点,也就是说:
设置以下操作:
It looks like this works if you explicitly set Basic authorization, that is, instead of:
set this:
您当前的curl发送GET请求(这就是外部API看不到发送的任何参数的原因),但您正在添加内容,因为它是POST请求。也添加
CURLOPT_POST
。Your current curl sends GET request (that's why external API does not see any parameters sent), but you are adding content as it's POST request. Add
CURLOPT_POST
too.