Use our API to connect your Application to img.ly

API v2 (recommended)

Note: This POST method will return 200 if everything went right. It will return a 401 Unauthorized if the OAuth header was not present or could not be verified with Twitter. It will return a 400 Bad Request if one of the required parameters is missing.

URL

http://img.ly/api/2/upload.format

Available Formats

xml, json

HTTP Method

POST

Headers

X-Verify-Credentials-Authorization (Required)
Header Example:
OAuth realm="http://api.twitter.com/",
oauth_consumer_key="abcdefghijklmnopqrst",
oauth_signature_method="HMAC-SHA1",
oauth_token="123456-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP",
oauth_timestamp="1234567890",
oauth_nonce="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
oauth_version="1.0",
oauth_signature="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO"

Header: X-Auth-Service-Provider (Required)
X-Auth-Service-Provider

https://api.twitter.com/1/account/verify_credentials.json

Parameters

  • message: The tweet that belongs to the image.
  • media (Required): The file upload data.

Responses

If you receive a HTTP 200 OK header, you can assume the image was successfully uploaded.


Sample XML Reponse
<?xml version="1.0" encoding="UTF-8"?>
<image>
    <id>3de</id>
    <text>some text</text>
    <url>http://img.ly/3de</url>
    <width>300</width>
    <height>200</height>
    <size>8211</size>
    <type>png</type>
    <timestamp>Wed, 2 June 2010 11:11:11 +0000</timestamp>
    <user>
        <id>123456</id>
        <screen_name>imglyuser</screen_name>
    </user>
</image>

Sample JSON Reponse
{
"id" : "3de",
"text" : "test",
"url" : "http:\/\/img.ly\/3de",
"width" : 300,
"height" : 200,
"size" : 8211,
"type" : "png",
"timestamp" : "Wed, 2 June 2010 11:11:11 +0000",
"user" : {
"id" : 123456,
"screen_name" : "imglytest"
}
}

Example CURL Command

curl -v -H 'X-Auth-Service-Provider: https://api.twitter.com/1/account/verify_credentials.json' -H 'X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/", oauth_consumer_key="abcdefghij", oauth_signature_method="HMAC-SHA1", oauth_token="123456-abcdefg", oauth_timestamp="1234567890", oauth_nonce="abcdef", oauth_version="1.0", oauth_signature="abcdefgh"' -F "media=@/path/to/image" http://img.ly/api/2/upload.json

API v1 (will be turned off on 30th of June)

URL

http://img.ly/api/uploadAndPost

Note: This method uploads an image to img.ly and posts it as a status update on Twitter

Pass following parameters, formatted as multipart/form-data:

  • media (required): Binary image data
  • username (required): Twitter username
  • password (required): Twitter password
  • message (optional): Message to post to twitter. The URL of the image is automatically added

Returns:

<?xml version="1.0" encoding="UTF-8"?>
<rsp stat="ok">
<statusid>1111</statusid>
<userid>11111</userid>
<mediaid>test123</mediaid>
<mediaurl>http://img.ly/abc123</mediaurl>
</rsp>

http://img.ly/api/upload

This method uploads an image to img.ly. No status update on Twitter.

Pass following parameters, formatted as multipart/form-data:

  • media (required): Binary image data
  • username (required): Twitter username
  • password (required): Twitter password

Returns:

<?xml version="1.0" encoding="UTF-8"?>
<rsp stat="ok">
<mediaid>test123</mediaid>
<mediaurl>http://img.ly/abc123</mediaurl>
</rsp>

Error Response

Sample Response:

<?xml version="1.0" encoding="UTF-8"?>
<rsp stat="fail">
<err code="1001" msg="Invalid twitter username or password" />
</rsp>

Error Codes:

  • 1001: Invalid twitter username or password
  • 1002: Image not found
  • 1003: Invalid image type
  • 1004: Image larger than 4MB

Image Thumbs

Format: http://img.ly/show/[mini|thumb|medium|large|full]/<image-id>

Example for a thumb URL: http://img.ly/show/thumb/3de

Even smaller thumb: http://img.ly/show/mini/3de

These URLs will redirect to the actual locations of the images

If you use those thumbnails, please link them to the corresponding image URL like

<a href="http://img.ly/3de">
<img src="http://img.ly/show/thumb/3de">
</a>

Append your application name to the updates sent from your API application!

If we should send your sourcekey instead of ours just send us (imgly@9elements.com) your sourcekey and a header which we can use to identify your app as a client and we'll make it work asap.

Questions? imgly _at_ 9elements.com