亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何通過php和curl正確獲取onedrive訪問令牌

如何通過php和curl正確獲取onedrive訪問令牌

PHP
哈士奇WWW 2021-11-26 16:31:18
我正在嘗試獲取 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, '', '&');


查看完整回答
反對 回復 2021-11-26
  • 1 回答
  • 0 關注
  • 271 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號