4

请有人可以帮助我使用 Live api。我需要从 OneDrive 获取所有照片。我不想使用“/me/albums”然后 foreach 专辑调用另一种方法。有没有办法解决这个问题。我错过了什么?我尝试谷歌,但链接已死。

谢谢你

4

2 回答 2

1

可能值得从Github 上的 PhotoSky 示例开始,它可以获取用户的所有照片。查看Data Model 文件夹中的代码,因为它具有从相册加载数据的功能,例如:

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);
        }
    }
于 2014-04-28T20:21:26.053 回答
0

据我所知,如果不进行迭代,就无法使用Live API ,这非常慢。您可以使用友好文件夹获取有限数量的图片

USER_ID/skydrive/camera_roll 代表 OneDrive 相机胶卷文件夹。USER_ID/skydrive/my_photos 代表图片文件夹。

但是,如果您切换到新的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){
  }];
}
于 2015-09-03T14:00:40.400 回答