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.
json_decode()
to create a map of the received data.json_encode()
.Here is an interactive API you can try out live to see the responses.
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.)
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).
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With