Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import UIKit
import XCPlayground
import Social
// Fetch image and convert JPEG data to base64 representation
let image = UIImage(named:"Quote")!
let base64String = UIImageJPEGRepresentation(image, 1.0).base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
// Establish post dictionary
var post = [NSObject:AnyObject]()
post["key"] = IMGUR_API_KEY
post["type"] = "base64"
post["image"] = base64String
// Create social request using a legal type (no particular reason to use Facebook in this case)
let url = NSURL(string:"")!
let slrequest = SLRequest(forServiceType: SLServiceTypeFacebook, requestMethod: SLRequestMethod.POST, URL: url, parameters: post)
// Set liveTest to true when you're ready to test with the real service
var liveTest = false
if liveTest {
(data, response, error) in
if let data = data,
dict = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue:0), error: nil) as? [String: AnyObject],
upload = dict["upload"] as? [String: AnyObject],
links = upload["links"] as? [String : AnyObject],
imgurPage = links["imgur_page"] as? String,
deletePage = links["delete_page"] as? String {
println("Image: \(imgurPage)")
println("Delete: \(deletePage)")
} else {
if let error = error {
} else {
// See run loop. See run loop run. Run, run loop, run!
XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment