Skip to main content

Windows Live - SkyDrive

Windows LIVE series:
Astazi o sa vorbim despre cum putem accesa SkyDrive.
Pentru a putea avea acces la datele pe care un user le are pe SkyDrive este nevoie ca la logare sa setam scopul "wl.skydrive". Avand setat acest scope o sa putem accesa orice informatie pe care userul o are pe SkyDrive.
WL.init({ client_id: {idClient}, redirect_uri: {ourRedirectUrl} });
WL.login(
{ "scope": "wl.skydrive" },
function (response) {
if (response.status == "connected") {
alert("Utilizator conectat");
}
else {
alert("Autentificare esuata");
}
});
Dupa ce utilizatorul s-a logat tot ce ne-a mai ramas este sa apelam API-ul care il avem la dispozitie. Fiecare element care ne vine dupa o interogare o sa contina date precum tipul ementului( daca e folder sau fisier - ce tip de fisier), nume fisier, id, dimensiune etc. Aceste informatii sunt foarte asemanatoare cu cele pe care le avem cand suntem intr-un director de pe disk-ul local. Din JS pentru a aduce toate elementele din root trebuie sa facem urmatorul apel:
 WL.api({ path: ""/me/skydrive/files", method: "GET" }, onGetRootItemsComplete);
function onGetRootItemsComplete(response) {
if (response.error) {
alert("A aparut o eroare");
return;
}
var items = response.data;
var foundFolder = 0;
for (var i = 0; i < items.length; i++)
{
// item[i].type - tipul fisierului. Valore este "fo-lder" daca elementul este un folder
// daca ar fi un fisier aceast camp ar avea valoarea "file"
// item[i].name - numele la element
// item[i].id - id unic a elementului din SkyDrive
}
}

O sa avem nevoie de id, daca vrem de exemplu sa facem download la continutul unui fisier.
Pentru a putea vedea toate folderele, albumele de poze si fisierele din root a unui user pe de Skydrive e nevoie sa facem un request cu path-ul setat spre: me/skydrive/files
Pentru a accesa fisierele unui folder este nevoie sa apelam urmatorul path: {folderId}/files . Exact la fel se face daca vrem sa aducem pozele dintr-un albul: {album_id}/files.
Dar cum putem sa adaugam un nou folder pe SkyDrive. Pentru acest lucru avem nevoie de numele la folder, o scurta descriere si locatia unde dorim sa il adaugam. Mai jos puteti gasi un exemplu in C#:
Dictionary<string, object> newFolderData = new Dictionary<string, object>();
folderData.Add("NewFolderName", "New folder description");
LiveConnectClient liveConnectClient = new LiveConnectClient(session);
liveConnectClient.PostCompleted +=
new EventHandler<LiveOperationCompletedEventArgs>(CreateFolderPostCompleted);
client.PostAsync("me/skydrive/files/BaseFolder", newFolderData);
...
void CreateFolderPostCompleted(object sender, LiveOperationCompletedEventArgs e)
{
// Daca e.Error este diferit de NULL, atunci actiunea nu s-a terminat cu succes.
}
Daca in al doilea exemplu am vazut cum putem itera printr-un folder, acuma va propun sa download un fisier de pe SkyDrive. Odata ce avem id-ul la fisierul pe care vrem sa il copiem local, e nevoie sa apelam direct metoda download din JS sau DownloadAsync din C#. Pentru exemplul de mai jos am ales tot varianta C#:
client.DownloadCompleted +=
new EventHandler<LiveDownloadCompletedEventArgs>(OnFileDownloadCompleted);
client.DownloadAsync("file.{id_fisier}/content");
...
void OnFileDownloadCompleted(object sender, LiveDownloadCompletedEventArgs e)
{
// e.Result o sa contina fisierul nostru.
// Nu uitati sa faceti close la Result, deoarece este un stream: e.Result.Close();
}
Dupa cum am putut vedea prin intermediul API-ului este foarte simplu sa lucram cu SkyDrive. Nu uitati ca SkyDrive nu permite prin intermediul API-ului upload-ul la orice fel de fisiere. Asigurativa inainte sa faceti upload ca fisierul vostru este suportat. Din interfata web puteti uploada orice fel de fisiere.
Fisierele care se pot copia pe SkyDrive prin intermediul API sunt:
  • PDF, txt + fisiere Office precum Word, Excell, etc
  • poze in orice format supotat de Windows
  • audio doar in format wav
  • video in format wmv sau H.264
Orice tip de fisier poate sa fie adaugat din brower de exemplu. Trebuie tinut cont ca, chiar daca din API manipulam datele unui user( schimba vizibilitatea unui fisier), nu putem sa restrictionam accesul la fisere a.i. userul sa nu le poata accesa.

Comments

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see

Navigating Cloud Strategy after Azure Central US Region Outage

 Looking back, July 19, 2024, was challenging for customers using Microsoft Azure or Windows machines. Two major outages affected customers using CrowdStrike Falcon or Microsoft Azure computation resources in the Central US. These two outages affected many people and put many businesses on pause for a few hours or even days. The overlap of these two issues was a nightmare for travellers. In addition to blue screens in the airport terminals, they could not get additional information from the airport website, airline personnel, or the support line because they were affected by the outage in the Central US region or the CrowdStrike outage.   But what happened in reality? A faulty CrowdStrike update affected Windows computers globally, from airports and healthcare to small businesses, affecting over 8.5m computers. Even if the Falson Sensor software defect was identified and a fix deployed shortly after, the recovery took longer. In parallel with CrowdStrike, Microsoft provided a too