apis
78 TopicsListing Files form OneDrive Using Python
Hello, I am trying to build an App in Python that automate files creation and deletion in OneDrive. I decided to use Microsoft Graph API for this. I wrote the following script to get started. import msal import requests import json # Define the MSAL application configuration client_id = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' authority = 'https://login.microsoftonline.com/common' scope = ['https://graph.microsoft.com/.default'] # Create a PublicClientApplication object app = msal.PublicClientApplication(client_id=client_id, authority=authority) # Check if the user has already signed in accounts = app.get_accounts() if accounts: # Get an access token silently result = app.acquire_token_silent(scope, account=accounts[0]) else: # Sign in and get an access token interactively result = app.acquire_token_interactive(scope) # Get the access token from the result access_token = result['access_token'] headers = {'Authorization': 'Bearer ' + access_token, 'Content-Type': 'application/json'} # url = "https://graph.microsoft.com/v1.0/me" # works just fine url = "https://graph.microsoft.com/v1.0/me/drive/root/children" # send a request response = requests.get(url,headers=headers) # check the status code of the response if response.status_code == requests.codes.ok: print(response.json()) else: # Print the error message if the request failed print(f'Request failed with status code: {response.status_code}') print(response.json()) Fetching the profile information using the URL in line 27 works as expected. However, listing the drive items using the URL in Line 28 gives the following error: {'error': {'code': 'itemNotFound', 'message': 'Item not found', 'innerError': {'date': '2023-04-07T11:58:04', 'request-id': '.........', 'client-request-id': '.........'}}} This is the App permission: Any idea what is going on?6.4KViews0likes1CommentSharing Folders with External Users spams Organization Login Prompts
In OneDrive, I can create a sharing link for a folder and set the link so "Anyone with the link can edit". I assume this means that even users outside my organization can edit the folders and files within the shared folder. If I test this with an external account, I'm able to edit the files and folders. However, I'm periodically prompted with a Microsoft login pop-up window. I can ignore/close the login prompt and continue editing the files. However, the login prompt keeps popping up periodically, including every time I refresh the screen. If I try to log in with the external user account, it gives me an error saying I'm not part of the tenant and I need to be added as an external user to the tenant. But then I can still close that and continue editing the files. If I send the invite link for a folder via a graph API call, I'm forced to set the "requireSignIn" property to True in the body of the request. If I set it to False, I get an error: RequireSignIn cannot be false for folders I do not run into the same issue when sharing files. Whether I create the link in OneDrive UI or via the API, the external user does not get hit repeatedly with login prompts. Am I doing something wrong or is this a bug? If sharing a folder is not allowed outside an organization, why does it allow me to create a sharing link where "Anyone with the link can edit"? And why is the external user still able to edit the files despite the repeated login prompts?4KViews0likes14CommentsBase URL used for Multi Tenants
Hello, I want users to select files from their personal and company drive but it requires a base url which is used to authenticate the user into the drive but the https://github.com/OneDrive/samples/tree/master/samples/file-picking and the https://learn.microsoft.com/en-us/onedrive/developer/controls/file-pickers/?view=odsp-graph-online don't have any indication of where to get a dynamic base url or the base url to use for the multiple tenants. Right now it only works for users in my organisation but I need it for users. Edit: I am using the v8 file picker Thank you3.8KViews1like5CommentsOneDrive Sync/Stop Sync - delete local files
Looking for a solution User syncs SPOL library User stops Sync Local file/folder structure remains - Looking for ideas on script that can run and delete those local files/folder once status goes from Sync to Stop Sync - The endpoints are intune Azure Joined - so we can push out a script - But first need to understand how OneDrive StopSync command communicates with the OS so I can use that as a trigger. Thanks, SJ2.6KViews0likes1CommentOne Drive Access Error: No Such Host is Known: SocketException (11001)
Hi, Some times, while generating access token, I'm getting the following error. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Http.HttpRequestException: No such host is known. ---> System.Net.Sockets.SocketException (11001): No such host is known. at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) This is the code, I'm using. string strURLForAccessToken = "https://login.microsoftonline.com/" + strOneDriveTenantId + "/oauth2/token"; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, strURLForAccessToken) { Content = new FormUrlEncodedContent(new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("grant_type", "password"), new KeyValuePair<string, string>("client_id", strClientId), new KeyValuePair<string, string>("client_secret", strClientSecret), new KeyValuePair<string, string>("resource", "https://graph.microsoft.com"), new KeyValuePair<string, string>("username", strUserName), new KeyValuePair<string, string>("password", strPassword) }) }; try { HttpResponseMessage strResponse = objHttpClient.SendAsync(request).GetAwaiter().GetResult(); string strResult = strResponse.Content.ReadAsStringAsync().Result; strNewAccessToken = JObject.Parse(strResult)["access_token"].ToString(); If I try after some time, with the same values, then this is fine. Why it is throwing error for first time? Please Help. Feel free to suggest any area of improvement in the above code.2.5KViews1like0CommentsHow do I share a person one drive file with a service account of azure
I am developing an application wherein a serverless function needs to access a one drive file of an external user who has shared the file with the app. The user is not connected with the domain in which the app is running. The approach I am taking is: In Azure create an AAD app and create a principal service. Create a secret. Using the client id, tenant id and secret value as credentials in a serverless function to access the required one drive file using microsoft graph api. Give permissions of File.Read.All to the principal service to use microsoft graph api However, with the above approach, I am facing the following issues: How does the user share the one drive file. User is not part of the app domain. I was hoping that the principal service will have an associated email id so that the user can do a private share with that id. The microsoft graph api seems to want an item-id. However, the url of the file (which is what is visible to the user) has a onedrive.live ...resid= .... cid= .... format. What is a item-id Thanks for any help on this issue.2.4KViews0likes1CommentUsers of our iOS app are receiving a Certificate Error when login to their OneDrive
Hi, On or around February 18th, users of our iOS App have started receiving a certificate error when attempting to sign in to their OneDrive accounts: "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “skyapi.onedrive.onedrive.live.com” which could put your confidential information at risk." Obviously, the URL looks incorrect (too many "onedrive."'s in there...). The trouble is this URL is generated by "accountchooser.js" (Microsoft written) in code that looks like this: e.skyApiBaseUrl = "https://skyapi.onedrive." + document.domain + "/API/2/"; We use the https://github.com/OneDrive/onedrive-sdk-ios via a Cocoapod (nothing has changed here in years) and our App hasn't changed anything here in a similar time frame. So something recent looks to have changed, either in the accountchooser.js code, or in how "document.domain" is calculated/determined on iOS. For reference, our users are seeing this on iOS 15.3.x and iOS 15.4, so latest stable production releases. Is anyone seeing anything similar? Any help with where or how we should raise this issue would be helpful... Who is the responsible team for accountchooser.js? Attached a screenshot of a Proxyman capture on a clean iOS Simulator Offending Code Related Threads and Issues Raised https://docs.microsoft.com/en-us/answers/questions/751860/onedrive-certificate-broken.html?childToView=752843#answer-752843 https://docs.microsoft.com/en-us/answers/questions/747693/users-of-our-ios-app-have-just-started-receiving-a.html https://twitter.com/StrongboxSafe/status/14964678064512860212KViews0likes2Comments