简体   繁体   English

将文件保存到OneDrive以获得商务/ Office365

[英]Save file to OneDrive for buisness/Office365

So the scenario is the following: User has connected to a datasource from where data is fetched on a scheduled basis. 因此,情况如下:用户已连接到数据源,并从该数据源中按计划获取数据。 Data is to be stored in the onedrive edition the users has - can be professional or onedrive bisness/office365. 数据将存储在用户拥有的onedrive版本中-可以是专业版本,也可以是onedrive bisness / office365。

so the idea is move data from data provider to data store (Onedrive personal/Business) on a scheduled basis by cron. 因此,想法是由cron按计划将数据从数据提供者移动到数据存储(Onedrive个人/企业)。

I managed this for personal however for business it only works on my own domain - if a customer signs up and want's to connect his/her office365 it fails. 我是个人管理的,但对于企业来说,它只能在我自己的域上工作-如果客户注册并希望连接他/她的office365,则它将失败。

Q1 what's the best api lib to use for PHP? Q1什么是用于PHP的最佳api库? Q2 is there any diffference other than the sign-in Q2除了登入外没有其他差异

br, Ditlev br,Ditlev

If there's an expert that is willing t olend me some tim eit would be much aprreciated. 如果有一位专家愿意跟我说些什么,那将是非常值得赞赏的。 Thanks. 谢谢。

Get the token by passing this url-> 通过传递此url->获得令牌

https://login.microsoftonline.com/common/oauth2/authorize?client_id=&response_type=code&redirect_uri=your-redirect-url&resource=https://graph.microsoft.com&client_secret= https://login.microsoftonline.com/common/oauth2/authorize?client_id=&response_type=code&redirect_uri=your-redirect-url&resource=https://graph.microsoft.com&client_secret=

get the accesstoken using the code by POST method url: https://login.microsoftonline.com/common/oauth2/token/ data to post: client_id=&code="code you got from previous request"&grant_type=authorization_code&redirect_uri=&resource= https://graph.microsoft.com&client_secret=&scope=Files.ReadWrite.All , Sites.ReadWrite.All, Web.Manage&content-type=application/x-www-form-urlencoded 使用POST方法网址的代码获取访问令牌: https ://login.microsoftonline.com/common/oauth2/token/要发布的数据:client_id =&code =“您从先前请求中获得的代码”&grant_type = authorization_code&redirect_uri =&resource = https ://graph.microsoft.com&client_secret=&scope=Files.ReadWrite.All,Sites.ReadWrite.All,Web.Manage&content-type = application / x-www-form-urlencoded

get the token from the array. 从数组中获取令牌。 this your authentication token. 这是您的身份验证令牌。

Upload file to onedrive -> 将文件上传到OneDrive->

you need to upload file using put method. 您需要使用put方法上传文件。

url: https://graph.microsoft.com/v1.0/me/drive/root:/foldername/filename:/content 网址: https ://graph.microsoft.com/v1.0/me/drive/root:/ foldername/ filename:/ content

pass this header: $headers = array( 'Content-Type: application/text', "Cache-Control: no-cache", "Pragma: no-cache", "Authorization: bearer ".$token ); 通过此标头:$ headers = array('Content-Type:application / text',“ Cache-Control:no-cache”,“ Pragma:no-cache”,“ Authorization:bearer”。$ token);

and pass the data from the file by file_get_contents. 并通过file_get_contents传递文件中的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM