我正在嘗試獲取 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 關注
- 271 瀏覽
添加回答
舉報
0/150
提交
取消