最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Microsoft Graph API v2 - Upload and Downlod files fromto OneDrive using PHP - Stack Overflow

programmeradmin1浏览0评论

All the sample code I can find for PHP + MS Graph relate to v1 which used a Graph object. Version 2 now uses a GraphServiceClient and the samples on MS make no sense to me at all. What I want to do is offer the ability for users of my Web Application the ability to store and retrieve documents using OneDrive instead of a database. I have created the multi-tennant application on my account with hopefully the right permissions. And that's as far as I have got. I would appreciate if anyone can point me at a site that has sample code using V2 of MS Graph on how to achieve that. I could be just too dumb, but MS seem to have made everything so complex.

The steps I imagine are as follows assuming I have an iframe where I list the files the user has uploaded to OneDrive thru my app. Metadata of the files are stored and indexed in my own database table. To upload a file they drag-drop a file on the page or browse and upload.

  • Step 1: get them to sign into OneDrive as their tenant by calling GraphServiceClient - with what sort of tokenRequestContext? Do I have to provide their tenant ID?
  • Step 2: wait for Graph to call the redirectUri, and store the token it provides in users Session variable?
  • Step 3: write an entry in the database table with metadata and get the unique ID to the file
  • Step 4: Upload the potentially large file by calling LargeFileUploadTask, file named with the ID from Step 3 for later retrieval. Does it matter if file size is less than 3mb?

Presumably steps 1 and 2 can be skipped if the oauth token exists in their session when next they upload a file, or do I do I have to do that anyway to check it hasn't timed out? The bit about maintaining your own InMemoryAccessTokenCache confuses me. Is that required? If I can figure that out, then I guess the download process should be easy.

发布评论

评论列表(0)

  1. 暂无评论