python3 upload files to ondrive or sharepoint?
<p>Anyone know if this is possible?
I just want to automate dropping some documents into my onedrive for business account.</p>

<p>I tried </p>

<pre><code>                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)
</code></pre>

<p>I registered an APP and got a secret and id. But when I ran this I got scope is invalid errors. Plus it tries to launch a webpage which isn't great for a command line kinda environment. I think this SDK might be outdated as well because originally this script had login.microsoftonline, but that wasn't reachable so I changed it to login.live.com.</p>

<p>I wrote this sample code you posted. You replaced the <code>auth_server_URL</code>with the authentication URL for Microsoft Account authentication, which can only be used to access OneDrive (the consumer product). You need to continue using the <code>login.microsoftonline.com</code> URL to log into your OneDrive for Business account.</p>

<p>You are correct that this pops up a dialog. However, you can write a little supporting code so that only happens the first time you log into a particular app. Follow these steps (assuming you are using the default implementation of <code>AuthProvider</code>:</p>

<ol>
<li>Use the sample code above up through the line <code>auth.redeem_refresh_token()</code></li>
<li>The <code>AuthProvider</code> will now have a <code>Session</code> object, which caches the credentials of the current user and session. Use <code>AuthProvider.save_session()</code> to save the credentials for later.</li>
<li>Next time you start your app, use <code>AuthProvider.load_session()</code> and <code>AuthProvider.refresh_token()</code> to retrieve the previous session and refresh the auth token. This will all be headless.</li>
</ol>

<p>Take note that the default implementation of <code>SessionBase</code> (<a href="https://github.com/OneDrive/onedrive-sdk-python/blob/master/src/onedrivesdk/session.py" rel="nofollow">found here</a>) uses <code>Pickle</code> and is not safe for product use. Make sure to create a new implementation of <code>Session</code> if you intend to deploy this app to other users.</p>

python python-3.x sharepoint upload onedrive