请帮助我使用Live api。我需要从OneDrive获取所有照片。我不想使用" / me / albums"然后foreach专辑调用另一种方法。是否有somu方法。我错过了什么?我试试谷歌但链接已经死了。
谢谢
答案 0 :(得分:1)
值得一提的是PhotoSky sample on Github,它可以获取所有用户的照片。看看Data Model folder中的代码,因为它具有从相册加载数据的功能,例如:
public async void LoadData()
{
LiveConnectClient client = new LiveConnectClient(App.Session);
LiveOperationResult albumOperationResult = await client.GetAsync("me/albums");
dynamic albumResult = albumOperationResult.Result;
foreach (dynamic album in albumResult.data)
{
var group = new SkyDriveAlbum(album.id, album.name, album.name, @"ms-appx:///Assets/DarkGray.png", album.description);
LiveOperationResult pictureOperationResult = await client.GetAsync(album.id + "/files");
dynamic pictureResult = pictureOperationResult.Result;
foreach (dynamic picture in pictureResult.data)
{
var pictureItem = new SkyDriveItem(picture.id, picture.name, picture.name, picture.source, picture.description, picture.description, group);
group.Items.Add(pictureItem);
}
this.AllGroups.Add(group);
}
}
答案 1 :(得分:0)
据我所知,使用 Live API ,如果不进行迭代,就无法做到这一点,这非常慢。您可以使用友好文件夹
获取有限数量的图片USER_ID / skydrive / camera_roll表示OneDrive相机胶卷文件夹。 USER_ID / skydrive / my_photos代表Pictures文件夹。
但是,如果您切换到新的 OneDriveSDK API,则相当简单。
- (void)getPhotos {
ODDriveAllPhotosRequest *allPhotosRequest = [[self.client.drive allPhotos] request];
if (![self.client serviceFlags][@"NoThumbnails"]){
[allPhotosRequest expand:@"thumbnails"];
}
[self loadPhotosWithRequest:allPhotosRequest];
}
- (void)loadPhotosWithRequest:(ODDriveAllPhotosRequest *)allPhotosRequest {
[allPhotosRequest executeWithCompletion:^(ODCollection *response, ODDriveAllPhotosRequest *nextRequest, NSError *error) {
if (!error){
if (response.value){
[self onLoadedPhotos:response.value];
}
if (nextRequest){
[self loadPhotosWithRequest:nextRequest];
}
}
else if ([error isAuthenticationError]){
[self showAlert:@"isAuthenticationError" message:error.localizedDescription];
[self onLoadedPhotos:@[]];
}
DDLogError(@"response %@ \n next request %@ \n error:%@",response,nextRequest,error);
}];
}
- (void)onLoadedPhotos:(NSArray *)photos
{
[photos enumerateObjectsUsingBlock:^(ODItem *item, NSUInteger index, BOOL *stop){
}];
}