4

pls can somebody help me with Live api. I need get all photos from OneDrive. I do not want use "/me/albums" and then foreach album call another methods. Is there somu method for that. I missing something? I try google but links are dead.

thank you

Lenny
  • 155
  • 3
  • 11

2 Answers2

1

It might be worth starting with the PhotoSky sample on Github which gets all of a user's photos. Take a look at the code in the Data Model folder because it has functions for loading data from an album, for instance:

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);
        }
    }
Jeanine M S
  • 448
  • 2
  • 8
  • I know that, but is slow get folders and then subfolders and then picture. I need only photos. Thats why I asking. – Lenny May 06 '14 at 16:39
0

As far as I can determine using the Live API you cannot do this without going iteratively, which is very slow. You can get a limited number of pictures by using the friendly folders

USER_ID/skydrive/camera_roll represents the OneDrive camera roll folder. USER_ID/skydrive/my_photos represents the Pictures folder.

However if you switch to the new OneDriveSDK API , it is fairly trivial.

- (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){
  }];
}
Ryan Heitner
  • 13,119
  • 6
  • 77
  • 119