Как исправить ошибку «ID3035: запрос недействителен или имеет неправильный формат». ошибка при загрузке файла в библиоте ⇐ Php
Как исправить ошибку «ID3035: запрос недействителен или имеет неправильный формат». ошибка при загрузке файла в библиоте
I'm trying to upload a file to a SharePoint document library using PHP and OAuth2 authentication. However, I'm getting an "ID3035: The request was not valid or is malformed." error. Here's my code:
// URL of the SharePoint site $site_url = 'https://usbbogedu.sharepoint.com/vacademica'; // Name of the document library where you want to upload the file $library_name = 'Plan de Trabajo'; // Name of the file you want to upload $file_name = 'mi-archivo.pdf'; // Full path of the file on your local system $file_path = '../subida_sp/Azul.jpg'; // OAuth2 authentication information $client_id = 'client_id '; $client_secret = 'client_secret '; $tenant_id = 'tenant_id'; $resource = 'https://usbbogedu.sharepoint.com'; // Get OAuth2 access token $auth_url = "https://login.microsoftonline.com/$tena ... uth2/token"; $ch = curl_init($auth_url); $data = array( 'grant_type' => 'client_credentials', 'client_id' => $client_id, 'client_secret' => $client_secret, 'resource' => $resource ); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if (false == $response) { echo "Error getting OAuth2 access token\n"; die(curl_error($ch)); } $token = json_decode($response)->access_token; // SharePoint API URL $url = $site_url . "/_api/web/lists/getbytitle('$library_name')/RootFolder/Files/add(url='$file_name',overwrite=true)"; // File content $file_content = file_get_contents($file_path); // Authentication headers with OAuth2 $headers = array( 'Authorization: Bearer ' . $token, 'Content-Type: application/octet-stream', 'Content-Length: ' . strlen($file_content) ); // HTTP POST request $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $file_content); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if (false == $response) { echo "Request failed\n"; $info = curl_getinfo($ch); foreach($info as $ent){ echo $ent . "
"; } } else { echo "Response ". $response ."\n"; curl_close($ch); $data = json_decode($response); } I have tried to upload a file to SharePoint using the provided code and have received the error message 'Respuesta {"error_description":"ID3035: The request was not valid or is malformed."}'. I have checked the credentials and they are correct. I was expecting the file to be uploaded successfully to the designated library in SharePoint. Can you please help me understand what could be causing this error?
Источник: https://stackoverflow.com/questions/759 ... ror-when-u
I'm trying to upload a file to a SharePoint document library using PHP and OAuth2 authentication. However, I'm getting an "ID3035: The request was not valid or is malformed." error. Here's my code:
// URL of the SharePoint site $site_url = 'https://usbbogedu.sharepoint.com/vacademica'; // Name of the document library where you want to upload the file $library_name = 'Plan de Trabajo'; // Name of the file you want to upload $file_name = 'mi-archivo.pdf'; // Full path of the file on your local system $file_path = '../subida_sp/Azul.jpg'; // OAuth2 authentication information $client_id = 'client_id '; $client_secret = 'client_secret '; $tenant_id = 'tenant_id'; $resource = 'https://usbbogedu.sharepoint.com'; // Get OAuth2 access token $auth_url = "https://login.microsoftonline.com/$tena ... uth2/token"; $ch = curl_init($auth_url); $data = array( 'grant_type' => 'client_credentials', 'client_id' => $client_id, 'client_secret' => $client_secret, 'resource' => $resource ); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if (false == $response) { echo "Error getting OAuth2 access token\n"; die(curl_error($ch)); } $token = json_decode($response)->access_token; // SharePoint API URL $url = $site_url . "/_api/web/lists/getbytitle('$library_name')/RootFolder/Files/add(url='$file_name',overwrite=true)"; // File content $file_content = file_get_contents($file_path); // Authentication headers with OAuth2 $headers = array( 'Authorization: Bearer ' . $token, 'Content-Type: application/octet-stream', 'Content-Length: ' . strlen($file_content) ); // HTTP POST request $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $file_content); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if (false == $response) { echo "Request failed\n"; $info = curl_getinfo($ch); foreach($info as $ent){ echo $ent . "
"; } } else { echo "Response ". $response ."\n"; curl_close($ch); $data = json_decode($response); } I have tried to upload a file to SharePoint using the provided code and have received the error message 'Respuesta {"error_description":"ID3035: The request was not valid or is malformed."}'. I have checked the credentials and they are correct. I was expecting the file to be uploaded successfully to the designated library in SharePoint. Can you please help me understand what could be causing this error?
Источник: https://stackoverflow.com/questions/759 ... ror-when-u
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение