Мне нужна помощь в понимании того, как я могу управлять библиотекой хранилища моего сайта SharePoint.
Учитывая, что у меня есть URL-адрес моего сайта «https://mycompanyname.sharepoint.com/sites/mysitename»
/>Сначала я хочу «получить доступ» к сайту, чтобы получить его идентификатор, чтобы позже получить диски под сайтом и управлять библиотекой хранения.
До сих пор я пробовал, безуспешно:
import os
import jwt
from typing import Optional, Literal
from azure.identity.aio import ClientSecretCredential
from msgraph import GraphServiceClient
from msgraph.generated.models.drive_item import DriveItem
from msgraph.generated.models.folder import Folder
from msgraph.generated.drives.item.items.item.content.content_request_builder import ContentRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
from msgraph.generated.models.o_data_errors.o_data_error import ODataError
from src.config.loader import CONFIG
import aiofiles
from src.utils.logger import get_logger
logger = get_logger(CONFIG.logging.name, CONFIG.logging.level)
class GraphClientSingleton():
_client = None
_credentials = None
@classmethod
def get_client(cls):
if cls._client is None:
# cls._authority = 'login.microsoftonline.com'
cls._credentials = ClientSecretCredential(
tenant_id = CONFIG.msgraph.tenant_id_sharepoint,
client_id = CONFIG.msgraph.client_id_sharepoint,
client_secret = CONFIG.msgraph.client_secret_sharepoint,
)
cls._scopes = ['https://graph.microsoft.com/.default']
cls._client = GraphServiceClient(credentials=cls._credentials, scopes=cls._scopes)
return cls._client
@classmethod
async def decode_token(cls):
token = await cls.get_access_token()
decoded_token = jwt.decode(token, options={"verify_signature": False})
return decoded_token
@classmethod
async def get_access_token(cls):
if cls._credentials is None:
cls.get_client()
token = await cls._credentials.get_token(*cls._scopes)
return token.token
class SharePointDAO:
def __init__(self):
self.client = GraphClientSingleton.get_client()
if __name__ == "__main__":
async def test_api():
token = await GraphClientSingleton.decode_token()
sp_dao = SharePointDAO()
# Example 1
from msgraph.generated.sites.sites_request_builder import SitesRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph ... abs=python
query_params = SitesRequestBuilder.SitesRequestBuilderGetQueryParameters(
select = ["siteCollection", "webUrl"],
filter = "siteCollection/root ne null",
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
sites = await sp_dao.client.sites.get(request_configuration = request_configuration)
# Example 2 (not sure how to map the "real" URL with the needed url here)
site_request_builder = sp_dao.client.sites.with_url(
"https://graph.microsoft.com/v1.0/sites/ ... mysitename"
)
site = await site_request_builder.get()
# Example 3 (return empty list under "value")
sites = await sp_dao.client.sites.get()
# Example 4 (return 403 error "Access Denied")
sites = await sp_dao.client.sites.get_all_sites.get()
logger.info(sites)
import asyncio
asyncio.run(test_api())
Подробнее здесь: https://stackoverflow.com/questions/792 ... python-sdk
Как получить/внести в список мой сайт SharePoint с помощью API-интерфейсов «Сайты» с помощью Python SDK ⇐ Python
Программы на Python
1734543746
Anonymous
Мне нужна помощь в понимании того, как я могу управлять библиотекой хранилища моего сайта SharePoint.
Учитывая, что у меня есть URL-адрес моего сайта «https://mycompanyname.sharepoint.com/sites/mysitename»
/>Сначала я хочу «получить доступ» к сайту, чтобы получить его идентификатор, чтобы позже получить диски под сайтом и управлять библиотекой хранения.
До сих пор я пробовал, безуспешно:
import os
import jwt
from typing import Optional, Literal
from azure.identity.aio import ClientSecretCredential
from msgraph import GraphServiceClient
from msgraph.generated.models.drive_item import DriveItem
from msgraph.generated.models.folder import Folder
from msgraph.generated.drives.item.items.item.content.content_request_builder import ContentRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
from msgraph.generated.models.o_data_errors.o_data_error import ODataError
from src.config.loader import CONFIG
import aiofiles
from src.utils.logger import get_logger
logger = get_logger(CONFIG.logging.name, CONFIG.logging.level)
class GraphClientSingleton():
_client = None
_credentials = None
@classmethod
def get_client(cls):
if cls._client is None:
# cls._authority = 'login.microsoftonline.com'
cls._credentials = ClientSecretCredential(
tenant_id = CONFIG.msgraph.tenant_id_sharepoint,
client_id = CONFIG.msgraph.client_id_sharepoint,
client_secret = CONFIG.msgraph.client_secret_sharepoint,
)
cls._scopes = ['https://graph.microsoft.com/.default']
cls._client = GraphServiceClient(credentials=cls._credentials, scopes=cls._scopes)
return cls._client
@classmethod
async def decode_token(cls):
token = await cls.get_access_token()
decoded_token = jwt.decode(token, options={"verify_signature": False})
return decoded_token
@classmethod
async def get_access_token(cls):
if cls._credentials is None:
cls.get_client()
token = await cls._credentials.get_token(*cls._scopes)
return token.token
class SharePointDAO:
def __init__(self):
self.client = GraphClientSingleton.get_client()
if __name__ == "__main__":
async def test_api():
token = await GraphClientSingleton.decode_token()
sp_dao = SharePointDAO()
# Example 1
from msgraph.generated.sites.sites_request_builder import SitesRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
query_params = SitesRequestBuilder.SitesRequestBuilderGetQueryParameters(
select = ["siteCollection", "webUrl"],
filter = "siteCollection/root ne null",
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
sites = await sp_dao.client.sites.get(request_configuration = request_configuration)
# Example 2 (not sure how to map the "real" URL with the needed url here)
site_request_builder = sp_dao.client.sites.with_url(
"https://graph.microsoft.com/v1.0/sites/mycompanyname.sharepoint.com:/mysitename"
)
site = await site_request_builder.get()
# Example 3 (return empty list under "value")
sites = await sp_dao.client.sites.get()
# Example 4 (return 403 error "Access Denied")
sites = await sp_dao.client.sites.get_all_sites.get()
logger.info(sites)
import asyncio
asyncio.run(test_api())
Подробнее здесь: [url]https://stackoverflow.com/questions/79292024/how-to-get-list-my-sharepoint-site-with-the-sites-apis-using-the-python-sdk[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия