Skip to content

Instantly share code, notes, and snippets.

@adactio
Created July 8, 2014 15:22
Show Gist options
  • Save adactio/a9c7e419b2913f318bd1 to your computer and use it in GitHub Desktop.
Save adactio/a9c7e419b2913f318bd1 to your computer and use it in GitHub Desktop.
<?php
# Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
# http://creativecommons.org/publicdomain/zero/1.0/
function postToFlickr($data=array()) {
$api_key = 'XXX';
$api_secret = 'XXXX';
$auth_token = 'XXXX';
$url = 'https://up.flickr.com/services/upload/';
$arguments = array(
'api_key' => $api_key,
'auth_token' => $api_secret,
'content_type' => 1,
'description' => '',
'hidden' => 1,
'is_public' => 1,
'safety_level' => 1,
'tags' => '',
'title' => ''
);
foreach ($data as $key => $value) {
if (array_key_exists($key, $arguments)) {
$arguments[$key] = $value;
}
}
$sig_string = $auth_token;
foreach($arguments as $key => $value) {
$sig_string.= $key;
$sig_string.= $value;
}
$api_sig = md5($sig_string);
$arguments['photo'] = $data['photo'];
$arguments['api_sig'] = $api_sig;
$options = array(
CURLOPT_HEADER => FALSE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $arguments,
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => 20,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTPHEADER => array('Expect:'),
CURLOPT_USERAGENT => 'adactio.com',
);
$curl = curl_init();
curl_setopt_array($curl, $options);
$result = curl_exec($curl);
curl_close($curl);
return json_decode(json_encode((array)simplexml_load_string($result)), true);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment