我正在尝试获取 onedrive 访问令牌。 这是请求:GET https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={client_id}&scope={scope} &response_type=token&redirect_uri={redirect_uri}这是回应:https://myapp.com/auth-redirect#access_token=EwC...EB &authentication_token=eyJ...3EM&token_type=bearer&expires_in=3600 &scope=onedrive.readwrite&user_id=3626...1d我已经在其他中实现了下面的两个代码来获取访问令牌,但是当页面被重定向以进行登录时出现以下错误。AADSTS900144:请求正文必须包含以下参数:“client_id”。范围属性以空格分隔,因此请参阅 onedrive 文档链接代码 1$data_string = array("client_id" => "myclient id","response_type" => "token","redirect_uri" => "http://localhost/test/callback.php""scope" => ['files.readwrite', 'offline_access'],); $data = json_encode($data_string); $curl = curl_init();curl_setopt_array($curl, array( CURLOPT_URL => "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_POSTFIELDS => "$data", ));$result = curl_exec($curl); $err = curl_error($curl);curl_close($curl);代码 2$curl = curl_init();curl_setopt_array($curl, array( CURLOPT_URL => "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=myclientid-goes-here&scope=files.readwrite.all offline_access &response_type=token&redirect_uri=http://localhost/test/callback.php", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", //CURLOPT_POSTFIELDS => "$data", ));$result = curl_exec($curl); $err = curl_error($curl);curl_close($curl);
1 回答
繁华开满天机
TA贡献1816条经验 获得超4个赞
这是使用http_build_query()函数解决的,因此
$data = http_build_query($data_string, '', '&');
- 1 回答
- 0 关注
- 244 浏览
添加回答
举报
0/150
提交
取消