In [1]:
import onedrivesdk
내 API의 권한 얻기
In [3]:
from onedrivesdk.helpers import GetAuthCodeServer
리디렉트 url, 비밀번호, 아이디 등 권한생성을 위한 준비
In [5]:
redirect_uri = "http://localhost:8080/"
In [6]:
client_secret = "wjOxKXxfnLQM73YjrECKTb0Pu7KR5al7"
변수 지정, 오프라인 접근, 읽고 쓰기 권한 부여받기
In [7]:
client = onedrivesdk.get_default_client(client_id='000000004C18A575',
scopes=['wl.signin',
'wl.offline_access',
'onedrive.readwrite'])
권한을 부여받은 url 변수지정
In [8]:
auth_url = client.auth_provider.get_auth_url(redirect_uri)
In [9]:
auth_url
Out[9]:
auth_url과 redirect_url을 통한 서버확인
In [36]:
code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
In [37]:
code
Out[37]:
In [35]:
client.auth_provider.authenticate(code, redirect_uri, client_secret)#?
onenote의 document폴더를 collection으로 지정
In [38]:
collection = client.item(drive="me", id="root").children.request().get()
In [53]:
collection
Out[53]:
In [54]:
collection[0].id
Out[54]:
In [55]:
collection[0].name
Out[55]:
document폴더 탐험하기, 내부파일을 dat로 지정
In [41]:
dat = client.item(drive="me", id= collection[0].id).children.get()
2번쨰 파일을 확인하기
In [42]:
dat[1].id
Out[42]:
In [43]:
dat[1].name
Out[43]:
'강연 160406 mssql' 구경하기
In [19]:
one = client.item(drive="me", id= dat[1].id).children.get()
In [44]:
one[1].id
Out[44]:
In [56]:
one[1].name
Out[56]:
In [45]:
id_of_file = one[1].id
드뎌 아이디 확인 '야호'
In [23]:
id_of_file
Out[23]:
콘텐츠 저장경로 확인~~
In [57]:
client.item(drive="me", id=id_of_file).content._request_url
Out[57]:
폴더 지정하여 txt파일로 다운로드
In [47]:
client.item(drive="me", id=id_of_file).download("C:\\data\\python1128\\test2.txt")
In [26]:
f = open('C:\\data\\python1128\\test2.txt', 'rb')
In [48]:
text =f.read()
In [49]:
text
Out[49]:
In [29]:
dir(f.read)
Out[29]:
In [50]:
text.encode('utf-8')
In [32]:
str(bytearray(text))
Out[32]:
In [33]:
str(text, "utf-8")
In [ ]: