1
我正在開發使用Windows 10 SDK的應用程序,我想使用Live SDK。我使用的是VS 2015,我已經通過nuget安裝了Live SDK。在Windows 10上開發通用應用程序時缺少實時SDK程序集引用
下面的代碼已採取從MSDN示例代碼:
LiveConnectClient liveClient;
private async Task<int> UploadFileToOneDrive()
{
try
{
// create OneDrive auth client
var authClient = new LiveAuthClient();
// ask for both read and write access to the OneDrive
LiveLoginResult result = await authClient.LoginAsync(new string[] { "wl.skydrive", "wl.skydrive_update" });
// if login successful
if (result.Status == LiveConnectSessionStatus.Connected)
{
// create a OneDrive client
liveClient = new LiveConnectClient(result.Session);
// create a local file
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("filename", CreationCollisionOption.ReplaceExisting);
// copy some txt to local file
MemoryStream ms = new MemoryStream();
DataContractSerializer serializer = new DataContractSerializer(typeof(string));
serializer.WriteObject(ms, "Hello OneDrive World!!");
using (Stream fileStream = await file.OpenStreamForWriteAsync())
{
ms.Seek(0, SeekOrigin.Begin);
await ms.CopyToAsync(fileStream);
await fileStream.FlushAsync();
}
// create a folder
string folderID = await GetFolderID("folderone");
if (string.IsNullOrEmpty(folderID))
{
// return error
return 0;
}
// upload local file to OneDrive
await liveClient.BackgroundUploadAsync(folderID, file.Name, file, OverwriteOption.Overwrite);
return 1;
}
}
catch
{
}
// return error
return 0;
}
public async Task<int> DownloadFileFromOneDrive()
{
try
{
string fileID = string.Empty;
// get folder ID
string folderID = await GetFolderID("folderone");
if (string.IsNullOrEmpty(folderID))
{
return 0; // doesnt exists
}
// get list of files in this folder
LiveOperationResult loResults = await liveClient.GetAsync(folderID + "/files");
List<object> folder = loResults.Result["data"] as List<object>;
// search for our file
foreach (object fileDetails in folder)
{
IDictionary<string, object> file = fileDetails as IDictionary<string, object>;
if (string.Compare(file["name"].ToString(), "filename", StringComparison.OrdinalIgnoreCase) == 0)
{
// found our file
fileID = file["id"].ToString();
break;
}
}
if (string.IsNullOrEmpty(fileID))
{
// file doesnt exists
return 0;
}
// create local file
StorageFile localFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("filename_from_onedrive", CreationCollisionOption.ReplaceExisting);
// download file from OneDrive
await liveClient.BackgroundDownloadAsync(fileID + "/content", localFile);
return 1;
}
catch
{
}
return 0;
}
問題是,即使安裝的NuGet後,LiveConnectClient是沒有得到認可。它的程序集引用缺失。當我嘗試通過添加引用來手動設置它時,它仍然沒有得到解決。 (難道是隻適用於Windows 8是什麼意思?)
的直播SDK信息如下所示的圖像:
的直播SDK是從這裏開始:https://github.com/liveservices/LiveSDK-for-Windows
我是什麼在這裏失蹤?
檢查是否引用了正確添加,[如果沒有,手動添加](http://stackoverflow.com/a/33215523/2681948)。 – Romasz
添加圖像參考的Live SDK – vip007
@Romasz:手動添加鏈接到Microsoft.Live.dll後,解決了這個問題。謝謝。但它仍然令人困惑,爲什麼VS不認識汽車。 – vip007