How to send folders and files within (Folders) and retrieve the already created folders from ONE DRIVE with Python?

Basicaly what im trying to do is create a Desktop app for create folders inside a shared folder from other account (ONE DRIVE) and send this new folder created with some files in it to the shared folder with python

What i did according to API App Registration AZURE is create a new register, all done, create the Secrets and Certs section and all this stuff i thinks is all good and done.

But in code what im did was this by now:

import tkinter as tk
from tkinter import filedialog, messagebox
import requests
import os
import msal

# Configuration - replace with your Azure app details
CLIENT_ID = 'XXXXXXXXXXXXXXXXXXXXXXXXX'
CLIENT_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXX'
TENANT_ID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
AUTHORITY = f'https://login.microsoftonline.com/{TENANT_ID}'
SCOPE = ['Files.ReadWrite.All', 'Sites.ReadWrite.All']
GRAPH_API_URL = 'https://graph.microsoft.com/v1.0'

# Initialize MSAL
app = msal.ConfidentialClientApplication(
    CLIENT_ID,
    authority=AUTHORITY,
    client_credential=CLIENT_SECRET
)

def get_access_token():
    result = app.acquire_token_for_client(scopes=SCOPE)
    return result.get('access_token')

def get_shared_folder_id(shared_folder_url):
    access_token = get_access_token()
    headers = {
        'Authorization': f'Bearer {access_token}'
    }
    response = requests.get(f'{GRAPH_API_URL}/sites/root/shared', headers=headers)
    if response.status_code == 200:
        items = response.json().get('value', [])
        for item in items:
            if item['webUrl'] == shared_folder_url:
                return item['id']
    return None

def create_folder(folder_name, parent_id):
    access_token = get_access_token()
    url = f'{GRAPH_API_URL}/drives/{parent_id}/items/root/children'
    headers = {
        'Authorization': f'Bearer {access_token}',
        'Content-Type': 'application/json'
    }
    data = {
        'name': folder_name,
        'folder': {},
        '@microsoft.graph.conflictBehavior': 'rename'
    }
    response = requests.post(url, headers=headers, json=data)
    if response.status_code == 201:
        messagebox.showinfo("Success", "Folder created successfully!")
    else:
        messagebox.showerror("Error", f"Failed to create folder: {response.json()}")

def upload_folder_to_shared():
    folder_path = filedialog.askdirectory()
    if not folder_path:
        return
    
    shared_folder_url = tk.simpledialog.askstring("Shared Folder URL", "Enter the URL of the shared folder:")
    if not shared_folder_url:
        return

    shared_folder_id = get_shared_folder_id(shared_folder_url)
    if not shared_folder_id:
        messagebox.showerror("Error", "Shared folder not found.")
        return

    folder_name = os.path.basename(folder_path)
    access_token = get_access_token()
    url = f'{GRAPH_API_URL}/drives/{shared_folder_id}/items/root/children'

    for root, dirs, files in os.walk(folder_path):
        for file in files:
            file_path = os.path.join(root, file)
            relative_path = os.path.relpath(file_path, folder_path)
            file_url = f'{url}/{relative_path}:/content'
            with open(file_path, 'rb') as f:
                response = requests.put(file_url, headers={
                    'Authorization': f'Bearer {access_token}'
                }, data=f)
                if response.status_code not in (200, 201):
                    messagebox.showerror("Error", f"Failed to upload {file}: {response.json()}")
                    return
    
    messagebox.showinfo("Success", "Files uploaded successfully!")

# Tkinter GUI setup
root = tk.Tk()
root.title("OneDrive Folder Manager")

# Upload folder UI
tk.Button(root, text="Upload Folder to Shared Folder", command=upload_folder_to_shared).pack()

root.mainloop()

This is what i did and it returns -> messagebox.showerror(“Error”, “Shared folder not found.”)
What am i doing wrong?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật