OneDrive API 获取所有照片

4

请问有人能帮我使用Live API吗?我想从OneDrive中获取所有照片,但不想使用“/me/albums”然后再对每个相册调用其他方法。是否有其他方法可以实现这个功能?我是漏掉了什么吗?我已经尝试过Google搜索,但链接都已失效。

谢谢!


你没有很努力地搜索,这个链接可能有帮助:http://msdn.microsoft.com/en-us/library/dn631819.aspx - Nathan
2个回答

1

建议从Github上的PhotoSky示例开始,该示例可以获取用户的所有照片。查看数据模型文件夹中的代码,因为它包含了从相册加载数据的函数,例如:

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);
        }
    }

我知道,但是获取文件夹、子文件夹和图片的速度很慢。我只需要照片。这就是我问的原因。 - Lenny

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){
  }];
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接