Skip to content

DRAFT: Get Photos API

dharFr edited this page Aug 18, 2012 · 7 revisions

Open Photo API / Get Photos

OpenPhoto, a photo service for the masses


  1. Purpose
  2. Endpoint
  3. Parameters
  4. Examples
  1. Response

Purpose of the Get Photos API

This API is used to download new photos for a user.


Endpoint

Authentication: optional

GET /photos/list.json

Parameters

  1. page (optional), Page number when browsing through photos. Starts at 1.
  2. tags (optional), i.e. dog,cat - A comma delimited string of alpha numeric strings.

Examples

Command line curl

curl http://jmathai.openphoto.me/photos/list.json

Posting a photo

curl -F 'photo=@/path/to/photo.jpg' -F 'tags=dog,cat' http://jmathai.openphoto.me/photo/upload.json
curl -F 'photo=base64_encoded_string_representation_of_photo' -F 'title=My first day at work' http://jmathai.openphoto.me/photo/upload.json

PHP

$ch = curl_init('http://jmathai.openphoto.me/photo/upload.json');
curl_setopt(
  $ch, 
  CURLOPT_POSTFIELDS, 
  array('photo' => '@/path/to/photo.jpg', 'tags' => 'dog,cat', returnOptions' => '300x300')
);
curl_exec($ch);
iOS
 - (void)searchPhotos{  
    // create the url to connect to OpenPhoto
    NSString *urlString = @"http://current.openphoto.me/photos/pageSize-25.json";
    NSURL *url = [NSURL URLWithString:urlString];

    responseData = [[NSMutableData alloc] init];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url];
[[NSURLConnection alloc] initWithRequest:request delegate:self];  
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Connection failed: %@", error);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
  [connection release];
  NSString *jsonString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  [responseData release];

  NSDictionary *results =  [jsonString JSONValue];
  [jsonString release];
  NSArray *photos = [results objectForKey:@"result"] ;
}

Response

The response is in a standard response envelope.

  • message, A string describing the result. Don't use this for anything but reading.
  • code, 200 on success
  • result, An array of Photo objects

Sample

{
  "message":"",
  "code":200,
  "result":[
    {
      "tags":[
         ""
      ],
      "pathBase":"\/base\/201107\/1311045184-opme7Z0WBh.jpg",
      "appId":"opme",
      "host":"testjmathai1.s3.amazonaws.com",
      "dateUploadedMonth":"07",
      "status":"1",
      "hash":"fba49a238426ac3485af6d69967ccd2d08c1fe5c",
      "width":"569",
      "dateTakenMonth":"07",
      "dateTakenDay":"18",
      "permission":"0",
      "pathOriginal":"\/original\/201107\/1311045184-opme7Z0WBh.jpg",
      "exifCameraMake":"",
      "size":"0",
      "dateTaken":"1311045184",
      "height":"476",
      "views":"0",
      "dateUploadedYear":"2011",
      "dateTakenYear":"2011",
      "creativeCommons":"BY-NC",
      "dateUploadedDay":"18",
      "dateUploaded":"1311045188",
      "exifCameraModel":"",
      "path200x200":"\/custom\/201107\/1311045184-opme7Z0WBh_200x200.jpg",
      "id":"hl"
    },
    {
      "tags":[
         ""
      ],
      "pathBase":"\/base\/201107\/1311027064-opme0WBhqP.jpg",
      "appId":"opme",
      "host":"testjmathai1.s3.amazonaws.com",
      "dateUploadedMonth":"07",
      "status":"1",
      "hash":"fba49a238426ac3485af6d69967ccd2d08c1fe5c",
      "width":"569",
      "dateTakenMonth":"07",
      "dateTakenDay":"18",
      "permission":"0",
      "pathOriginal":"\/original\/201107\/1311027064-opme0WBhqP.jpg",
      "exifCameraMake":"",
      "size":"0",
      "dateTaken":"1311027064",
      "height":"476",
      "views":"0",
      "dateUploadedYear":"2011",
      "dateTakenYear":"2011",
      "creativeCommons":"BY-NC",
      "dateUploadedDay":"18",
      "dateUploaded":"1311027066",
      "exifCameraModel":"",
      "id":"ob"
    }
  ]
}