使用PHP和OAuth访问SkyDrive的 [英] Access SkyDrive using PHP and OAuth

查看:240
本文介绍了使用PHP和OAuth访问SkyDrive的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用PHP来访问SkyDrive的。
我想中检索文件和文件夹,下载列表,上传,删除文件。

我有一个微软开发clientID的和clientSecret。

任何人可以让我开始与连接到SkyDrive OAuth并利用该API的?

非常感谢!


解决方案

这其实是一个相当宽泛的问题。这里有希望的东西,将让你开始。


  1. 看一看 Sk​​yDrives REST API

  2. 您可以使用 PHP卷曲来执行GET的和POST的。

  3. 使用 json_de code () 创建地图接收到的数据的。

  4. 为你发送任何数据,创建地图在PHP 并转换他们JSON使用 json_en code ()


尝试API

这是一个互动的API,你可以尝试一下现场看到的响应。


发出请求

(从其他了这么回答)的:

  $ URL ='POST https://apis.live.net/v5.0/me/skydrive/files';
$ CH = curl_init();
curl_setopt($ CH,CURLOPT_URL,$网址);
curl_setopt($ CH,CURLOPT_POSTFIELDS,阵列('ACCESS_TOKEN'=>的道理,'名'=>'文件','名'=>中@ HelloWorld.txt));
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,真正的);
$结果= curl_exec($ CH);
curl_close($ CH);

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

我也建议你看看 curl_setopt( ) ,以更好地了解如何做不同类型的,知道你们需要的请求,使用卷曲。 (也因此这个答案对POST一些很好的解释VS GET使用卷曲。)


File对象


  • 删除文件:


      

    要删除一个文件,做一个DELETE请求/ FILE_ID。



  • 上传文件:


      

    要创建一个新的文件资源,你可以做一个POST请求/ FOLDER_ID /文件,一个POST请求/ UPLOAD_LOCATION目标文件夹,或PUT请求/ FOLDER_ID /文件/.



  • 下载文件:


      

    要获取属性文件的资源,做一个GET请求/ FILE_ID(目标文件ID)。



    • 文件资源将包含要从中SkyDrive的下载文件中的来源字段中的URL。



Folder对象


  • 检索文件列表:


      

    要使用实时连接REST API获取根文件夹的资源,做一个GET请求到/我/的SkyDrive或/ USER_ID / SkyDrive的。


      
      

    要得到一个子文件夹中的资源,做一个GET请求/ FOLDER_ID。



  • 创建文件夹:


      

    要创建一个新的文件夹的资源,做一个POST请求/ FOLDER_ID。通过名称和描述属性在请求体



  • 删除文件夹:


      

    要删除文件夹,做一个DELETE请求/ FOLDER_ID。




的OAuth 2.0

我与OAuth的经验,不幸的限制。我只能提供一些相关的链接和建议,我希望会有所帮助。

查看协议概述,如果你要考虑实现自己的东西,或使用图书馆。快速谷歌搜索给我:

一些其他潜在有用的链接和指南:

I would like to access skyDrive using PHP. I want to retreive list of files and folders, download, upload and delete files.

I've got a microsoft dev clientID and clientSecret.

Can anybody get me started with connecting to skyDrive with OAuth and making use of the API?

Thanks a lot!

解决方案

This is actually quite a broad question. Here's hopefully something that will get you started.

  1. Have a look at SkyDrives REST API.
  2. You could use PHP cURL to perform the GET's and POST's.
  3. Use json_decode() to create a map of the received data.
  4. For any data you send, create maps in PHP and convert them to JSON using json_encode().


Try the API

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


Making requests

Example (taken from other SO Answer):

$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);

Request types: http://msdn.microsoft.com/en-us/library/live/hh243648.aspx#http_verbs

I also recommend you have a look at curl_setopt() to better understand how to do the different types of requests you'll be needing, using cURL. (Also this answer on SO has some good explanation on POST vs GET using cURL.)


File object

  • DELETE FILES:

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

  • UPLOAD FILES:

    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/.

  • DOWNLOAD FILES:

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

    • The File resource will contain the URL from which to download the file from SkyDrive in the source field.


Folder object

  • RETRIEVE LIST OF FILES:

    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.

  • CREATE FOLDERS:

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

  • DELETE FOLDERS:

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


OAuth 2.0

My experience with OAuth is unfortunately limited. I can only provide some relevant links and advice which I hope will help.

Review the Protocol Overview and consider if you want to implement something yourself, or use a library. Quick Google search gives me:

Some other potentially useful links and guides:

这篇关于使用PHP和OAuth访问SkyDrive的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆