加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

使用PHP和OAuth访问SkyDrive

发布时间:2020-12-13 18:10:45 所属栏目:PHP教程 来源:网络整理
导读:我想使用 PHP访问skyDrive. 我想要检索文件和文件夹列表,下载,上传和删除文件. 我有一个microsoft开发者clientID和clientSecret. 任何人都可以开始使用OAuth连接到skyDrive并使用API??吗? 非常感谢! 这实际上是一个非常广泛的问题.希望有些东西能让你开始.
我想使用 PHP访问skyDrive.
我想要检索文件和文件夹列表,下载,上传和删除文件.

我有一个microsoft开发者clientID和clientSecret.

任何人都可以开始使用OAuth连接到skyDrive并使用API??吗?

非常感谢!

这实际上是一个非常广泛的问题.希望有些东西能让你开始.

>看看SkyDrives REST API.
>您可以使用PHP cURL执行GET和POST.
>使用json_decode()创建接收数据的映射.
>对于您发送的任何数据,使用PHP创建maps并使用json_encode()将它们转换为JSON.

试试API

Here is an interactive API you can try out live to see the responses.

发出请求

Example(取自其他SO答案):

$url = 'POST https://apis.live.net/v5.0/me/skydrive/files';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,array('access_token' => TOKEN,'name' => 'file','filename' => "@HelloWorld.txt"));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$result = curl_exec($ch);
curl_close($ch);

请求类型:http://msdn.microsoft.com/en-us/library/live/hh243648.aspx#http_verbs

我还建议您查看curl_setopt(),以便更好地了解如何使用cURL执行您需要的不同类型的请求. (Also this answer on SO has some good explanation on POST vs GET using cURL.)

File object

>删除文件:

To delete a file,make a DELETE request to /FILE_ID.

>上传文件:

To create a new File resource,you can either make a POST request to /FOLDER_ID/files,a POST request to the /UPLOAD_LOCATION for the target folder,or a PUT request to /FOLDER_ID/files/.

>下载文件:

To get properties for a File resource,make a GET request to /FILE_ID (the target file ID).

>文件资源将包含从源字段中从SkyDrive下载文件的URL.

Folder object

>检索文件列表:

To get the root Folder resource by using the Live Connect REST API,make a GET request to either /me/skydrive or /USER_ID/skydrive.

To get a subfolder resource,make a GET request to /FOLDER_ID.

>创建文件夹:

To create a new Folder resource,make a POST request to /FOLDER_ID. Pass the name and description attributes in the request body

>删除文件夹:

To delete a folder,make a DELETE request to /FOLDER_ID.

OAuth 2.0

不幸的是,我对OAuth的体验有限.我只能提供一些相关的链接和建议,希望对此有所帮助.

Review the Protocol Overview并考虑是否要自己实现某些内容,或使用库.快速谷歌搜索给了我:

> http://code.google.com/p/google-api-php-client/wiki/OAuth2
> http://code.google.com/p/oauth2-php/
> http://php.net/manual/en/book.oauth.php

其他一些可能有用的链接和指南:

>参见http://oauth.net/code/的PHP部分

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读