function uploadFile(OpenPhotoOAuth $client, syncLogger $logger, $exiftran, $hashs, $file) { $expTitle = explode('/', $file); $title = array_pop($expTitle); $dir = array_pop($expTitle); if (substr($dir, 0, 1) == '[' && substr($dir, -1, 1) == ']') { $mainTag = substr($dir, 14, -1); } elseif (substr($dir, 4, 1) == '-' && substr($dir, 10, 1) == '_') { $mainTag = substr($dir, 11); } else { $mainTag = substr($dir, 11); } $tags = $mainTag . ',__synchronised__'; $title = $dir . '/' . $title; if (!isFileUploaded($exiftran, $hashs, $file)) { $logger->log(sprintf('[uploading] %s', $file)); $r = $client->post('/photo/upload.json', array('photo' => base64_encode(file_get_contents($file)), 'title' => $title, 'tags' => $tags)); $result = json_decode($r); if (null === $result) { $logger->log('[error] Error getting /photo/upload.json'); return; } if ($result->code != 201) { $logger->log(sprintf('[error] [%s] %s', $result->code, $result->message)); } } else { $logger->log(sprintf('[existing] %s', $file)); } }
<?php ### script to make all photos private (e.g. if you accidentally upload some ### ### assumes you've exported your credentials into the environment variables noted ### $consumerKey = getenv('consumerKey'); $consumerSecret = getenv('consumerSecret'); $token = getenv('token'); $tokenSecret = getenv('tokenSecret'); ### ### change value to your own openphoto hostname ### $host = 'kkweng.openphoto.me'; ### ### to list all photos set pageSize to zero ### $endpoint = '/photos/pageSize-0/list.json'; include 'OpenPhotoOAuth.php'; $client = new OpenPhotoOAuth($host, $consumerKey, $consumerSecret, $token, $tokenSecret); $allPhotos = json_decode($client->get($endpoint)); if (!$allPhotos->result) { echo "Error: " . $allPhotos->message . "\n"; exit(2); } foreach ($allPhotos->result as $myres) { $myID = $myres->id; $endpoint = "/photo/" . $myID . "/update.json"; $resp = json_decode($client->post($endpoint, array('permission' => '0'))); echo "photo<{$myID}>: code<" . $resp->code . "> message <" . $resp->message . ">\n"; }
* * oauth_token * * oauth_token_secret */ require './OpenPhotoOAuth.php'; require './secrets.php'; require './util.php'; if (isset($_GET['oauth_consumer_key']) && isset($_GET['oauth_consumer_secret']) && isset($_GET['oauth_token']) && isset($_GET['oauth_token_secret'])) { $hostParts = parse_url($_SERVER['HTTP_REFERER']); if (!empty($hostParts['host'])) { $client = new OpenPhotoOAuth($hostParts['host'], $_GET['oauth_consumer_key'], $_GET['oauth_consumer_secret'], $_GET['oauth_token'], $_GET['oauth_token_secret']); // exchange unauthorized access token for an authorized access token $resp = $client->post('/v1/oauth/token/access', array('oauth_verifier' => $_GET['oauth_verifier'])); parse_str($resp, $tokens); $id = md5(time()); $sth = $dbh->prepare("INSERT INTO `{$mysqltable}`(id, email) \n VALUES(:id, :email)", array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $status = $sth->execute(array(':id' => $id, ':email' => $_GET['email'])); if ($status) { $authClient = new OpenPhotoOAuth($hostParts['host'], $_GET['oauth_consumer_key'], $_GET['oauth_consumer_secret'], $tokens['oauth_token'], $tokens['oauth_token_secret']); // subscribe a webhook $response = $authClient->post('/webhook/subscribe', array('callback' => "http://{$_SERVER['HTTP_HOST']}/callback.php?id={$id}", 'topic' => 'photo.upload', 'mode' => 'sync')); if (empty($response)) { header('Location: /?success'); die; } } else { var_dump($sth->errorInfo()); die; } } } echo "Something went wrong";