μ’μ μ€νμμ,
μ λ λΌμ΄λΈλ¬λ¦¬μμ μΌλΆ νλͺ©μ μ°Ύμ λ€μ΄λ‘λν μ μλ μ¬κ· 루νμ λν΄ μμ ν΄ μμ΅λλ€.
μ§κΈκΉμ§ λͺ¨λ μμλ₯Ό ββμ»μ μ μμμ§λ§ μμμ μμ±μ "μ΄λ¦" νλκ° λνλμ§ μκΈ° λλ¬Έμ λ€μ΄λ‘λν μ μμ΅λλ€.
μμλ₯Ό νμΌλ‘ λ³νν λ μμ±μ΄ null({})μ΄λ―λ‘ μ΄λ¦μ κ°μ Έμ¬ μ μμ΅λλ€.
file.dowload() λ©μλλ νμΌμ μꡬνκ³ νμΌμ νμ¬ νμ₯μλ₯Ό λͺ¨λ₯΄κΈ° λλ¬Έμ νμΌμ λ€μ΄λ‘λνλ κ²μ κ±°μ λΆκ°λ₯ν©λλ€.
μ΄λ€ μ μ?
λ΄κ° μ¬μ©νλ μ½λλ λ€μκ³Ό κ°μ΅λλ€.
from office365.runtime.auth.ClientCredential import ClientCredential
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.file import File
from office365.sharepoint.camlQuery import CamlQuery
ctx = ClientContext.connect_with_credentials(site_url, ClientCredential(client_id, client_secret))
lib = ctx.web.lists.get_by_title("XXX")
caml_query = CamlQuery()
caml_query.ViewXml = """XXX"""
items = lib.get_items(caml_query)
ctx.load(lib)
ctx.execute_query()
for item in items:
file = item.file
with open(download_path, "wb") as local_file:
file.download(local_file)
ctx.execute_query()
print("[Ok] file has been downloaded: {0}".format(download_path))
미리 κ°μ¬λ립λλ€!
μλ νμΈμ,
λλ λ΄ λ¬Έμ λ₯Ό ν΄κ²°ν μ μμλ€.
νλͺ© λͺ©λ‘ λ΄μμ λ°λ³΅ν ν κ° νμΌμ λν 컨ν μ€νΈλ₯Ό νΈμΆν΄μΌ νλ©° μ΄λ¦μ΄ ν¬ν¨λ νμΌμ μμ±μ κ²μν λ€μ νμΌμ λ€μ΄λ‘λν μ μμ΅λλ€.
μ΄κ²μ μλ λ΄ μ½λμ λλ€.
client_id = "XXX"
client_secret = "XXX"
site_url = "XXX"
download_folder = r'C:\Users\yourname\sharepoint'
from office365.runtime.auth.ClientCredential import ClientCredential
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.file import File
from office365.sharepoint.camlQuery import CamlQuery
ctx = ClientContext.connect_with_credentials(site_url, ClientCredential(client_id, client_secret))
lib = ctx.web.lists.get_by_title("REO")
caml_query = CamlQuery()
caml_query.ViewXml = XXX
items = lib.get_items(caml_query)
ctx.load(items)
ctx.execute_query()
for item in items:
file = item.file
ctx.load(file)
ctx.execute_query()
file_name = "{0}".format(file.properties["Name"])
download_path = download_folder + '//' + file_name
with open(download_path, "wb") as local_file:
file.download(local_file)
ctx.execute_query()
print("[Ok] file has been downloaded: {0}".format(download_path))
@pobs93 μμ€ μ½λλ₯Ό μ¬μ©νμ¬ Sharepoint λͺ©λ‘μμ μ²¨λΆ νμΌμ λ€μ΄λ‘λνλ €κ³ ν©λλ€.
μ΄λ€ 맀κ°λ³μλ₯Ό μ¬μ©ν μ§ λͺ¨λ₯΄κΈ° λλ¬Έμ μ΄ μ€μ μ£Όμμ λ¬μμ΅λλ€.
caml_query.ViewXml = XXX
κ·Έλ¬λ μ½λλ₯Ό μ€νν λ ctx.execute_query()
νμμ μλ μ€λ₯κ° λ°μν©λλ€.
TypeError: CamlQuery μ νμ κ°μ²΄λ JSON μ§λ ¬ν κ°λ₯νμ§ μμ΅λλ€.
μ λ μ΄λ° μ νμ APIμ μ΅μνμ§ μμμ λͺ
ννκ² μ€λͺ
ν μ μλμ§ κΆκΈν©λλ€.
TKS
@pobs93 μ²¨λΆ νμΌμ λ€μ΄λ‘λνλ €λ λͺ©λ‘μ λν μ€λͺ
μ μΆκ°νκΈ°λ§ νλ©΄ λ©λλ€.
κ·Έκ²λ€μ λ΄κ° κ°μ§κ³ μλ λͺ©λ‘μ DEFAULT ν€μ΄λ©° μ¬κΈ°μ μ²¨λΆ νμΌμ URLμ΄ νμλμ§ μμ§λ§ κ±°κΈ°μ μμ΅λλ€(첨λΆλ κ·Έλ¦Ό μ°Έμ‘°).
{'νμΌ μμ€ν
κ°μ²΄ μ ν': -,
'ID': -,
'ServerRedirectedEmbedUri': μμ,
'ServerRedirectedEmbedUrl': '',
'μ½ν
μΈ μ ν ID': -,
'μ λͺ©': -,
'ComplianceAssetId': μμ,
'ID': -,
'μμ λ¨': -,
'λ§λ€μ΄μ§': -,
'μ μ ID': 12,
'EditorId': 12,
'OData__UIVersionString': '1.0',
'첨λΆνμΌ': μ¬μ€,
'GUID': -}
λ€μ μλ λͺ©λ‘ νλͺ©μ λν _file name_ λ° _file url_μ κ²μνλ λ°©λ²μ 보μ¬μ€λλ€.
ctx = ClientContext(settings['url']).with_credentials(client_creds)
lib = ctx.web.lists.get_by_title("Documents")
items = lib.items
ctx.load(items, ["ID", "FileLeafRef", "FileRef"])
ctx.execute_query()
for item in items:
print(f"FileRef: {item.properties['FileRef']}")
μ΄λ
FileLeafRef
- ListItemκ³Ό μ°κ²°λ νμΌ λ
Έλμ μλ² μλ URLμ λν μ λ³΄κ° ν¬ν¨λ νλλ₯Ό μλ³ν©λλ€.
FileRef
- ListItemμ μλ² μλ URLμ λν μ λ³΄κ° ν¬ν¨λ νλλ₯Ό μλ³ν©λλ€.
κ°μ₯ μ μ©ν λκΈ
μλ νμΈμ,
λλ λ΄ λ¬Έμ λ₯Ό ν΄κ²°ν μ μμλ€.
νλͺ© λͺ©λ‘ λ΄μμ λ°λ³΅ν ν κ° νμΌμ λν 컨ν μ€νΈλ₯Ό νΈμΆν΄μΌ νλ©° μ΄λ¦μ΄ ν¬ν¨λ νμΌμ μμ±μ κ²μν λ€μ νμΌμ λ€μ΄λ‘λν μ μμ΅λλ€.
μ΄κ²μ μλ λ΄ μ½λμ λλ€.