任何人都知道這是否可能? 我只想自動將一些文檔放入我的onedrive for business帳戶。python3上傳文件到ondrive或sharepoint?
我試圖
import onedrivesdk
from onedrivesdk.helpers import GetAuthCodeServer
from onedrivesdk.helpers.resource_discovery import ResourceDiscoveryRequest
redirect_uri = 'http://localhost:8080'
client_id = 'appid'
client_secret = 'mysecret'
discovery_uri = 'https://api.office.com/discovery/'
auth_server_url='https://login.live.com/oauth20_authorize.srf?scope=wl.skydrive_update'
#auth_server_url='https://login.microsoftonline.com/common/oauth2/authorize',
auth_token_url='https://login.microsoftonline.com/common/oauth2/token'
http = onedrivesdk.HttpProvider()
auth = onedrivesdk.AuthProvider(http,
client_id,
auth_server_url=auth_server_url,
auth_token_url=auth_token_url)
auth_url = auth.get_auth_url(redirect_uri)
code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
auth.authenticate(code, redirect_uri, client_secret, resource=resource)
# If you have access to more than one service, you'll need to decide
# which ServiceInfo to use instead of just using the first one, as below.
service_info = ResourceDiscoveryRequest().get_service_info(auth.access_token)[0]
auth.redeem_refresh_token(service_info.service_resource_id)
client = onedrivesdk.OneDriveClient(service_info.service_resource_id + '/_api/v2.0/', auth, http)
我註冊一個APP,並有一個祕密和ID。但是當我跑這個我得到範圍是無效的錯誤。另外它會嘗試啓動一個不適合命令行環境的網頁。我認爲這個SDK可能也過時了,因爲最初這個腳本有login.microsoftonline,但是這是無法訪問的,所以我將它改爲login.live.com。
所以它應該是爲企業工作賬戶呢?在這條線上的代碼扼流圈,並永遠留在這裏: '>>> auth_url = auth.get_auth_url(redirect_uri)' 我在Mac上使用原始代碼,除了祕密和應用程序id變量, python 2.7 –
我的不好,我很抱歉,代碼停在'code = GetAuthCodeServer.get_auth_code(auth_url,redirect_uri)',下一行 –