App42

Photo Gallery Service

This module enables you to create your own photo gallery on the cloud where you can create, retrieve, remove and manage your photo albums. This service is very useful for developers who want to integrate Photo Gallery functionality in their Mobile/Device and Web Apps. Gallery API gives a complete Photo Gallery service and reduces the footprint on the device so that you can focus on other Gallery aspects such as how to render the Photo Gallery thereby reducing development time. Functions available in Gallery API are listed below:

Import Statement

  1. using com.shephertz.app42.paas.sdk.csharp;
  2. using com.shephertz.app42.paas.sdk.csharp.gallery;

Initialize

Download Android SDK, if you have not downloaded yet.

In order to use the various functions available in a specific API, the developer has to initialize with App42API by passing the apiKey and the secretKey which will become available after the app creation from AppHQ dashboard.

Required Parameters

apiKey - The Application key given when the application was created.secretKey - The secret key corresponding to the application key given when the application was created.

  1. App42API.Initialize(“API_KEY”,“SECRET_KEY”);

Build Service

After initialization, the developer will have to call the buildXXXService method on App42API to get the instance of the particular API that they wish to build. For example, to build an instance of Album Service, buildAlbumService() method needs to be called.

  1. AlbumService albumService = App42API.BuildAlbumService();
  2. PhotoService photoService = App42API.BuildPhotoService();

Create Albums

Create Album on the cloud.

Required Parameters

userName - The user to whom the album belongs.albumName - Name of the album to be created on the cloud.description - Description of the album to be created.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. String description = “Album Description”;
  4. App42Log.SetDebug(true);        //Prints output in your editor console
  5. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  6. AlbumService albumService = App42API.BuildAlbumService();
  7. albumService.CreateAlbum(userName, albumName, description, new UnityCallBack());
  8. public class UnityCallBack : App42CallBack
  9. {
  10.     public void OnSuccess(object response)
  11.     {
  12.         Album album = (Album) response;
  13.         App42Log.Console(“userName is :” + album.GetUserName());
  14.         App42Log.Console(“albumName is :” + album.GetName());
  15.         App42Log.Console(“Description is :” + album.GetDescription());
  16.         App42Log.Console(“jsonResponse is :” + album.ToString());
  17.     }
  18.     public void OnException(Exception e)
  19.     {
  20.         App42Log.Console(“Exception : “ + e);
  21.     }
  22. }

Get Albums

Fetch all the albums based on the username.

Required Parameters

userName - Name of the user whose albums have to be fetched.

  1. String userName = “Nick”;
  2. App42Log.SetDebug(true);        //Prints output in your editor console
  3. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  4. AlbumService albumService = App42API.BuildAlbumService();
  5. albumService.GetAlbums(userName, new UnityCallBack());
  6. public class UnityCallBack : App42CallBack
  7. {
  8.     public void OnSuccess(object response)
  9.     {
  10.         IList<Album> album = (IList<Album>) response;
  11.         for(int i = 0; i < album.Count; i++)
  12.         {
  13.         App42Log.Console(“userName is :” + album[i].GetUserName());
  14.         App42Log.Console(“albumName is :” + album[i].GetName());
  15.         App42Log.Console(“Description is :” + album[i].GetDescription());
  16.         App42Log.Console(“jsonResponse is :” + album[i].ToString());
  17.         }
  18.     }
  19.     public void OnException(Exception e)
  20.     {
  21.         App42Log.Console(“Exception : “ + e);
  22.     }
  23. }

Get Albums Count

Fetch the count of all the Albums based on the username.

userName - The user for which the count of albums have to be fetched.

  1. String userName = “Nick”;
  2. App42Log.SetDebug(true);        //Prints output in your editor console
  3. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  4. AlbumService albumService = App42API.BuildAlbumService();
  5. albumService.GetAlbumsCount(userName, new UnityCallBack());
  6. public class UnityCallBack : App42CallBack
  7. {
  8.     public void OnSuccess(object response)
  9.     {
  10.         App42Response app42Response = (App42Response) response;
  11.         App42Log.Console(“app42Response is :” + app42Response.ToString());
  12.     }
  13.     public void OnException(Exception e)
  14.     {
  15.         App42Log.Console(“Exception : “ + e);
  16.     }
  17. }

Get Albums Paging

Fetch all the albums based on the username by paging.

Required Parameters

userName - Name of the user whose albums have to be fetched.max - Maximum number of records to be fetched.offset - From where the records are to be fetched.

  1. String userName = “Nick”;
  2. int max = 1;
  3. int offset = 0 ;
  4. App42Log.SetDebug(true);        //Prints output in your editor console
  5. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  6. AlbumService albumService = App42API.BuildAlbumService();
  7. albumService.GetAlbums(userName,max,offset, new UnityCallBack());
  8. public class UnityCallBack : App42CallBack
  9. {
  10.     public void OnSuccess(object response)
  11.     {
  12.         IList<Album> album = (IList<Album>) response;
  13.         for(int i = 0; i < album.Count; i++)
  14.         {
  15.         App42Log.Console(“userName is :” + album[i].GetUserName());
  16.         App42Log.Console(“albumName is :” + album[i].GetName());
  17.         App42Log.Console(“Description is :” + album[i].GetDescription());
  18.         App42Log.Console(“jsonResponse is :” + album[i].ToString());
  19.         }
  20.     }
  21.     public void OnException(Exception e)
  22.     {
  23.         App42Log.Console(“Exception : “ + e);
  24.     }
  25. }

Get Album By Name

Fetch album details based on the username.

Required Parameters

userName - Name of the user whose albums have to be fetched.albumName - Name of the album that has to be fetched.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. App42Log.SetDebug(true);        //Prints output in your editor console
  4. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  5. AlbumService albumService = App42API.BuildAlbumService();
  6. albumService.GetAlbumByName(userName,albumName, new UnityCallBack());
  7. public class UnityCallBack : App42CallBack
  8. {
  9.     public void OnSuccess(object response)
  10.     {
  11.         Album album = (Album) response;
  12.         App42Log.Console(“userName is :” + album.GetUserName());
  13.         App42Log.Console(“albumName is :” + album.GetName());
  14.         App42Log.Console(“Description is :” + album.GetDescription());
  15.         App42Log.Console(“jsonResponse is :” + album.ToString());
  16.     }
  17.     public void OnException(Exception e)
  18.     {
  19.         App42Log.Console(“Exception : “ + e);
  20.     }
  21. }

Add Photo

Add photo for a particular user and album. The photo is uploaded on the cloud.

Required Parameters

userName - Name of the user whose photo has to be added.albumName - Name of the album in which photo has to be added.photoName - Name of the photo that has to be added.description - Description of the photo that has to be added.filePath - The local path for the file.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. String photoName = “My Photo”;
  4. String description = “Photo Details”;
  5. String filePath    = “Your Local file path”;
  6. App42Log.SetDebug(true);        //Prints output in your editor console
  7. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  8. PhotoService photoService = App42API.BuildPhotoService();
  9. photoService.AddPhoto(userName, albumName, photoName, description, filePath, new UnityCallBack());
  10. public class UnityCallBack : App42CallBack
  11. {
  12.     public void OnSuccess(object response)
  13.     {
  14.         Album album = (Album) response;
  15.         App42Log.Console(“userName is :” + album.GetUserName());
  16.         App42Log.Console(“albumName is :” + album.GetName());
  17.         App42Log.Console(“Description is :” + album.GetDescription());
  18.         App42Log.Console(“jsonResponse is :” + album.ToString());
  19.         IList<Album.Photo> photoList = album.GetPhotoList();;
  20.         for(int i = 0; i < photoList.Count; i++)
  21.         {
  22.             App42Log.Console(“PhotoName is :” + photoList[i].GetName());
  23.             App42Log.Console(“Url is :” + photoList[i].GetUrl());
  24.             App42Log.Console(“TinyUrl is :” + photoList[i].GetTinyUrl());
  25.             App42Log.Console(“ThumbNailUrl is :” + photoList[i].GetThumbNailUrl());
  26.             App42Log.Console(“ThumbNailTinyUrl is :” + photoList[i].GetThumbNailTinyUrl());
  27.             App42Log.Console(“jsonResponse is :” + photoList[i].ToString());
  28.         }
  29.     }
  30.     public void OnException(Exception e)
  31.     {
  32.         App42Log.Console(“Exception : “ + e);
  33.     }
  34. }

Add Tag To Photo

Add tags to the photos for the user in the album.

Required Parameters

userName - Name of the user whose photo has to be tagged.albumName - Name of the album whose photo is to be tagged.photoName - Name of the photo to be tagged.tagList - List of tags in Photo.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. String photoName = “My Photo”;
  4. IList<String> tagList = new List<String>();
  5. tagList.Add(“John”);
  6. App42Log.SetDebug(true);        //Prints output in your editor console
  7. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  8. PhotoService photoService = App42API.BuildPhotoService();
  9. photoService.AddTagToPhoto(userName,albumName,photoName,taglist, new UnityCallBack());
  10. public class UnityCallBack : App42CallBack
  11. {
  12.     public void OnSuccess(object response)
  13.     {
  14.         Album album = (Album) response;
  15.         App42Log.Console(“userName is :” + album.GetUserName());
  16.         App42Log.Console(“albumName is :” + album.GetName());
  17.         App42Log.Console(“Description is :” + album.GetDescription());
  18.         App42Log.Console(“jsonResponse is :” + album.ToString());
  19.         IList<Album.Photo> photoList = album.GetPhotoList();;
  20.         for(int i = 0; i < photoList.Count; i++)
  21.         {
  22.         App42Log.Console(“PhotoName is :” + photoList[i].GetName());
  23.         App42Log.Console(“Url is :” + photoList[i].GetUrl());
  24.         App42Log.Console(“TinyUrl is :” + photoList[i].GetTinyUrl());
  25.         App42Log.Console(“ThumbNailUrl is :” + photoList[i].GetThumbNailUrl());
  26.         App42Log.Console(“ThumbNailTinyUrl is :” + photoList[i].GetThumbNailTinyUrl());
  27.         App42Log.Console(“jsonResponse is :” + photoList[i].ToString());
  28.         }
  29.     }
  30.     public void OnException(Exception e)
  31.     {
  32.         App42Log.Console(“Exception : “ + e);
  33.     }
  34. }

Get Photos

Fetch all the photos based on the username.

Required Parameters

userName - Name of the user whose photos have to be fetched.

  1. String userName = “Nick”;
  2. App42Log.SetDebug(true);        //Prints output in your editor console
  3. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  4. PhotoService photoService = App42API.BuildPhotoService();
  5. photoService.GetPhotos(userName, new UnityCallBack());
  6. public class UnityCallBack : App42CallBack
  7. {
  8.     public void OnSuccess(object response)
  9.     {
  10.         Album album = (Album) response;
  11.         App42Log.Console(“userName is :” + album.GetUserName());
  12.         App42Log.Console(“albumName is :” + album.GetName());
  13.         App42Log.Console(“Description is :” + album.GetDescription());
  14.         App42Log.Console(“jsonResponse is :” + album.ToString());
  15.         IList<Album.Photo> photoList = album.GetPhotoList();;
  16.         for(int i = 0; i < photoList.Count; i++)
  17.         {
  18.         App42Log.Console(“PhotoName is :” + photoList[i].GetName());
  19.         App42Log.Console(“Url is :” + photoList[i].GetUrl());
  20.         App42Log.Console(“TinyUrl is :” + photoList[i].GetTinyUrl());
  21.         App42Log.Console(“ThumbNailUrl is :” + photoList[i].GetThumbNailUrl());
  22.         App42Log.Console(“ThumbNailTinyUrl is :” + photoList[i].GetThumbNailTinyUrl());
  23.         App42Log.Console(“jsonResponse is :” + photoList[i].ToString());
  24.         }
  25.     }
  26.     public void OnException(Exception e)
  27.     {
  28.         App42Log.Console(“Exception : “ + e);
  29.     }
  30. }

Get Tagged Photos

Fetche all the photos based on the username and tag.

Required Parameters

userName - Name of the user for which the albums have to be fetched.tag - Tag on which basis photos have to be fetched.

  1. String userName = “Nick”;
  2. String tag = “John”;
  3. App42Log.SetDebug(true);        //Prints output in your editor console
  4. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  5. PhotoService photoService = App42API.BuildPhotoService();
  6. photoService.GetTaggedPhotos(userName, tag, new UnityCallBack());
  7. public class UnityCallBack : App42CallBack
  8. {
  9.     public void OnSuccess(object response)
  10.     {
  11.         IList<Album> album = (IList<Album>) response;
  12.         for(int i=0; i < album.Count; i++)
  13.         {
  14.         App42Log.Console(“userName is :” + album[i].GetUserName());
  15.         App42Log.Console(“albumName is :” + album[i].GetName());
  16.         App42Log.Console(“Description is :” + album[i].GetDescription());
  17.         App42Log.Console(“jsonResponse is :” + album[i].ToString());
  18.         }
  19.     }
  20.     public void OnException(Exception e)
  21.     {
  22.         App42Log.Console(“Exception : “ + e);
  23.     }
  24. }

Get Photos By Album Name

Fetche all photos based on the username and album name.

Required Parameters

userName - Name of the user whose photos have to be fetched.albumName - Name of the album from which photos have to be fetched.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. App42Log.SetDebug(true);        //Prints output in your editor console
  4. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  5. PhotoService photoService = App42API.BuildPhotoService();
  6. photoService.GetPhotosByAlbumName(userName,albumName, new UnityCallBack());
  7. public class UnityCallBack : App42CallBack
  8. {
  9.     public void OnSuccess(object response)
  10.     {
  11.         Album album = (Album) response;
  12.         App42Log.Console(“userName is :” + album.GetUserName());
  13.         App42Log.Console(“albumName is :” + album.GetName());
  14.         App42Log.Console(“Description is :” + album.GetDescription());
  15.         App42Log.Console(“jsonResponse is :” + album.ToString());
  16.         IList<Album.Photo> photoList = album.GetPhotoList();
  17.         for(int i=0; i < photoList.Count; i++)
  18.         {
  19.         App42Log.Console(“Photo List jsonResponse is : “ + photoList[i].ToString());
  20.         App42Log.Console(“Name is : “ + photoList[i].GetName());
  21.         App42Log.Console(“ThumbNailUrl is : “ + photoList[i].GetThumbNailUrl());
  22.         App42Log.Console(“ThumbNailTinyUrl is : “ + photoList[i].GetThumbNailTinyUrl());
  23.         App42Log.Console(“Url is : “ + photoList[i].GetUrl());
  24.         App42Log.Console(“TinyUrl is : “ + photoList[i].GetTinyUrl());
  25.         }
  26.     }
  27.     public void OnException(Exception e)
  28.     {
  29.         App42Log.Console(“Exception : “ + e);
  30.     }
  31. }

Get Photos By Album Name (Paging)

Fetches all photos based on the username and album name by paging.

Required Parameters

userName - Name of the user whose photos have to be fetched.albumName - Name of the album from which photos have to be fetched.max - Maximum number of records to be fetched.offset - From where the records are to be fetched.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. int max = 1;
  4. int offset = 0;
  5. App42Log.SetDebug(true);        //Prints output in your editor console
  6. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  7. PhotoService photoService = App42API.BuildPhotoService();
  8. photoService.GetPhotosByAlbumName(userName,albumName,max,offset, new UnityCallBack());
  9. public class UnityCallBack : App42CallBack
  10. {
  11.     public void OnSuccess(object response)
  12.     {
  13.         Album album = (Album) response;
  14.         App42Log.Console(“userName is :” + album.GetUserName());
  15.         App42Log.Console(“albumName is :” + album.GetName());
  16.         App42Log.Console(“Description is :” + album.GetDescription());
  17.         App42Log.Console(“jsonResponse is :” + album.ToString());
  18.         IList<Album.Photo> photoList = album.GetPhotoList();
  19.         for(int i=0; i < photoList.Count; i++)
  20.         {
  21.         App42Log.Console(“Photo List jsonResponse is : “ + photoList[i].ToString());
  22.         App42Log.Console(“Name is : “ + photoList[i].GetName());
  23.         App42Log.Console(“ThumbNailUrl is : “ + photoList[i].GetThumbNailUrl());
  24.         App42Log.Console(“ThumbNailTinyUrl is : “ + photoList[i].GetThumbNailTinyUrl());
  25.         App42Log.Console(“Url is : “ + photoList[i].GetUrl());
  26.         App42Log.Console(“TinyUrl is : “ + photoList[i].GetTinyUrl());
  27.         }
  28.     }
  29.     public void OnException(Exception e)
  30.     {
  31.         App42Log.Console(“Exception : “ + e);
  32.     }
  33. }

Get Photos Count By Album Name

Fetche the count of all Photos based on the username and album name.

Required Parameters

userName - Name of the user whose count of photos have to be fetched.albumName - Name of the album from which count of photos have to be fetched.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. App42Log.SetDebug(true);        //Prints output in your editor console
  4. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  5. PhotoService photoService = App42API.BuildPhotoService();
  6. photoService.GetPhotosCountByAlbumName(userName,albumName, new UnityCallBack());
  7. public class UnityCallBack : App42CallBack
  8. {
  9.     public void OnSuccess(object response)
  10.     {
  11.         App42Response app42Response = (App42Response) response;
  12.         App42Log.Console(“app42Response is :” + app42Response.ToString());
  13.     }
  14.     public void OnException(Exception e)
  15.     {
  16.         App42Log.Console(“Exception : “ + e);
  17.     }
  18. }

Get Photos By Album Name And Photo Name

Fetch the photo details based on the username, album name and photo name.

Required Parameters

userName - Name of the user whose photo has to be added.albumName - Name of the album in which photo has to be added.photoName - Name of the photo that has to be added.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. String photoName = “My Photo”;
  4. App42Log.SetDebug(true);        //Prints output in your editor console
  5. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  6. PhotoService photoService = App42API.BuildPhotoService();
  7. photoService.GetPhotosByAlbumAndPhotoName(userName, albumName, photoName, new UnityCallBack());
  8. public class UnityCallBack : App42CallBack
  9. {
  10.     public void OnSuccess(object response)
  11.     {
  12.         Album album = (Album) response;
  13.         App42Log.Console(“userName is :” + album.GetUserName());
  14.         App42Log.Console(“albumName is :” + album.GetName());
  15.         App42Log.Console(“Description is :” + album.GetDescription());
  16.         App42Log.Console(“jsonResponse is :” + album.ToString());
  17.         IList<Album.Photo> photoList = album.GetPhotoList();
  18.         for(int i=0; i < photoList.Count; i++)
  19.         {
  20.         App42Log.Console(“Photo List jsonResponse is : “ + photoList[i].ToString());
  21.         App42Log.Console(“Name is : “ + photoList[i].GetName());
  22.         App42Log.Console(“ThumbNailUrl is : “ + photoList[i].GetThumbNailUrl());
  23.         App42Log.Console(“ThumbNailTinyUrl is : “ + photoList[i].GetThumbNailTinyUrl());
  24.         App42Log.Console(“Url is : “ + photoList[i].GetUrl());
  25.         App42Log.Console(“TinyUrl is : “ + photoList[i].GetTinyUrl());
  26.         }
  27.     }
  28.     public void OnException(Exception e)
  29.     {
  30.         App42Log.Console(“Exception : “ + e);
  31.     }
  32. }

Remove Album

Remove the album based on the username and album name. Note : All photos in this album will also be removed.

Required Parameters

userName - User whose album has to be removed.albumName - Name of the album that has to be removed.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. App42Log.SetDebug(true);        //Prints output in your editor console
  4. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  5. PhotoService photoService = App42API.BuildPhotoService();
  6. photoService.RemoveAlbum(userName,albumName, new UnityCallBack());
  7. public class UnityCallBack : App42CallBack
  8. {
  9.     public void OnSuccess(object response)
  10.     {
  11.         App42Response app42Response = (App42Response) response;
  12.         App42Log.Console(“app42Response is :” + app42Response.ToString());
  13.     }
  14.     public void OnException(Exception e)
  15.     {
  16.         App42Log.Console(“Exception : “ + e);
  17.     }
  18. }

Remove Photo

Remove the particular photo from the specified album for a particular user. Note : The photo is removed from the cloud and won’t be accessible in future.

Required Parameters

userName - Name of the user whose photo has to be removed.albumName - Name of the album in which photo has to be removed.photoName - Name of the photo that has to be removed.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. String photoName = “My Photo”;
  4. App42Log.SetDebug(true);        //Prints output in your editor console
  5. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  6. PhotoService photoService = App42API.BuildPhotoService();
  7. photoService.RemovePhoto(userName,albumName,photoName, new UnityCallBack());
  8. public class UnityCallBack : App42CallBack
  9. {
  10.     public void OnSuccess(object response)
  11.     {
  12.         App42Response app42Response = (App42Response) response;
  13.         App42Log.Console(“app42Response is :” + app42Response.ToString());
  14.     }
  15.     public void OnException(Exception e)
  16.     {
  17.         App42Log.Console(“Exception : “ + e);
  18.     }
  19. }

Update Photo

Update existing photo for a particular user and album. Note Only Photo and description will be changed(Photo Name will remain the same).

Required Parameters

userName - Name of the user whose photo has to be updated.albumName - Name of the album in which photo has to be updated.photoName - Name of the photo that has to be update.description - Description of the photo that has to be updated.filePath - Path from where photo has to be picked for addition.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. String photoName = “My Photo”;
  4. String description = “Photo Details”;
  5. String filePath = “Your Local file path”;
  6. App42Log.SetDebug(true);        //Prints output in your editor console
  7. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  8. PhotoService photoService = App42API.BuildPhotoService();
  9. photoService.UpdatePhoto(userName, albumName, photoName, description, filePath, new UnityCallBack());
  10. public class UnityCallBack : App42CallBack
  11. {
  12.     public void OnSuccess(object response)
  13.     {
  14.         Album album = (Album) response;
  15.         App42Log.Console(“userName is :” + album.GetUserName());
  16.         App42Log.Console(“albumName is :” + album.GetName());
  17.         App42Log.Console(“Description is :” + album.GetDescription());
  18.         App42Log.Console(“jsonResponse is :” + album.ToString());
  19.         IList<Album.Photo> photoList = album.GetPhotoList();;
  20.         for(int i = 0; i < photoList.Count; i++)
  21.         {
  22.         App42Log.Console(“PhotoName is :” + photoList[i].GetName());
  23.         App42Log.Console(“Url is :” + photoList[i].GetUrl());
  24.         App42Log.Console(“TinyUrl is :” + photoList[i].GetTinyUrl());
  25.         App42Log.Console(“ThumbNailUrl is :” + photoList[i].GetThumbNailUrl());
  26.         App42Log.Console(“ThumbNailTinyUrl is :” + photoList[i].GetThumbNailTinyUrl());
  27.         App42Log.Console(“jsonResponse is :” + photoList[i].ToString());
  28.         }
  29.     }
  30.     public void OnException(Exception e)
  31.     {
  32.         App42Log.Console(“Exception : “ + e);
  33.     }
  34. }

Exception Handling

The functions available under Gallery API can throw some exceptions in abnormal conditions. For example, if a developer is creating an album for the user which is not in database, the function will throw the App42Exception (as shown below) with message as “Not Found” and the appErrorCode as “2500” and the details as “The request parameters are invalid. Album with the name ‘My Album’ for the user ‘Nick’ already exists”.

  1. String userName = “Nick”;
  2. String albumName = “My Album”;
  3. String albumDescription = “Album Description”;
  4. App42Log.SetDebug(true);        //Prints output in your editor console
  5. App42API.Initialize(“API_KEY”,“SECRET_KEY”);
  6. PhotoService photoService = App42API.BuildPhotoService();
  7. photoService.CreateAlbum(userName,albumName,albumDescription, new UnityCallBack());
  8. public class UnityCallBack : App42CallBack
  9. {
  10.     public void OnException(Exception e)
  11.     {
  12.        App42Exception exception = (App42Exception)e;
  13.        int appErrorCode = exception.GetAppErrorCode();
  14.        int httpErrorCode = exception.GetHttpErrorCode();
  15.     if(appErrorCode == 2500)
  16.     {
  17.         // Handle here for Bad Request (The request parameters are invalid. Album with the name ‘@My Album’ for the user ‘@userName’ already exists.)
  18.     }
  19.     else if(appErrorCode == 1401){
  20.         // handle here for Client is not authorized
  21.     }
  22.     else if(appErrorCode == 1500){
  23.         // handle here for Internal Server Error
  24.     }
  25.     String jsonText = exception.GetMessage();
  26.     }
  27.     public void OnSuccess(object response)
  28.     {
  29.         App42Log.Console(“response is :” + response.ToString());
  30.     }
  31. }

Error Codes

Functions in Gallery API might throw exceptions with following HTTP and Application Error Codes (along with their descriptions):

1400 - BAD REQUEST - The requested parameters are invalid.1401 - UNAUTHORIZED - Client is not authorized.1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again.2500 - BAD REQUEST - The request parameters are invalid. Album with the name '@albumName' for the user '@userName' already exists.2501 - NOT FOUND - Album by the name '@albumName' for the user '@userName' does not exist.2502 - NOT FOUND - Albums for the user '@userName' do not exist.2503 - NOT FOUND - Albums and Photos for the user '@userName' does not exist.2504 - NOT FOUND - Photo with the name '@photoName' from the Album '@albumName' for the user '@userName' does not exist.2505 - BAD REQUEST - The request parameters are invalid. Photo by the name '@photoName' for album '@albumName' for the user '@userName' already exists.2506 - NOT FOUND - The number of albums for the user '@userName' are less than the specified offset : + "offset".2507 - NOT FOUND - Album by the name '@albumName' for the user '@userName' have less photos than the specified offset : + "offset".2508 - NOT FOUND - Albums and Photos for the tag '@tag' does not exist.