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.
- Have a look at SkyDrives REST API.
- You could use PHP cURL to perform the GET’s and POST’s.
json_decode()to create a map of the received data.
- For any data you send, create maps in PHP and convert them to JSON using
Try the API
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);
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.)
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).
- The File resource will contain the URL from which to download the file from SkyDrive in the source field.
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.
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.
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:
- See PHP section of http://oauth.net/code/