View Single Post
Old June 17th, 2017, 05:03 PM   #4
herkalurk
Vintage Member
 
herkalurk's Avatar
 
Join Date: Apr 2011
Location: Tulsa
Posts: 23,168
Thanks: 609
Thanked 275,128 Times in 23,048 Posts
herkalurk 1000000+herkalurk 1000000+herkalurk 1000000+herkalurk 1000000+herkalurk 1000000+herkalurk 1000000+herkalurk 1000000+herkalurk 1000000+herkalurk 1000000+herkalurk 1000000+herkalurk 1000000+
Default

It appears that you're not making galleries..?

Just wondering. I was going to work on redoing my upload scripts after I had downloaded and sorted my images from imagebam. I had used PHP to do my previous upload script. I would just point it to a folder and it would upload each image in that folder ascending alphabetically.

Script would take 2 arguements: name of gallery, folder path

I was planning to retrofit some pieces into a new script to upload for pixhost that way you could note your gallery links and use them.

Code:
<?php
$ID=$argv[1];
$gal_ID=NULL;
function gallery($gallery)
{
global $gal_ID;
// required parameters for the OAuth-authentication
// replace all parameters!
$API_key = "ABCD1234";
$API_secret = "ABCD1234";
$on1=rand(10000000,99999999);
$oauth_nonce = "$on1";
$oauth_token = "ABCD1234";
$oauth_token_secret = "ABCD1234";
$oauth_timestamp = time();
$oauth_signature_method = "MD5";
#$oauth_consumer_key = "1RSF4O2X";
// build the signature string
$oauth_signature_string = "";
$oauth_signature_string .= $API_key;
$oauth_signature_string .= $API_secret;
$oauth_signature_string .= $oauth_timestamp;
$oauth_signature_string .= $oauth_nonce;
$oauth_signature_string .= $oauth_token;
$oauth_signature_string .= $oauth_token_secret;


// calculate the MD5-checksum of the signature string
$oauth_signature = md5($oauth_signature_string);

// populate an array with parameters
$gal_vars   = array(
        // parameters required by OAuth
        "oauth_consumer_key" => $API_key,
        "oauth_signature_method" => $oauth_signature_method,
        "oauth_signature" => $oauth_signature,
        "oauth_timestamp" => $oauth_timestamp,
        "oauth_nonce" => $oauth_nonce,
        "oauth_token" => $oauth_token,

        // optional parameters
        "response_format" => "JSON",
        "title" => "$gallery",
);

// initialize curl and set parameters
$gal_curl    = curl_init();
curl_setopt($gal_curl, CURLOPT_URL, 'http://www.imagebam.com/sys/API/resource/create_gallery');
curl_setopt($gal_curl, CURLOPT_TIMEOUT, 30);
curl_setopt($gal_curl, CURLOPT_POST, 1);
curl_setopt($gal_curl, CURLOPT_POSTFIELDS, $gal_vars);
curl_setopt($gal_curl, CURLOPT_RETURNTRANSFER, true);

// execute, get information and close connection
$gal_response = curl_exec($gal_curl);
$info = curl_getinfo($gal_curl);
curl_close ($gal_curl);


// check if the http-code is 200
if($info['http_code'] != 200) {
    exit("OAuth error: ".$gal_response);
}

// decode the json-encoded response
$gal_response_array = json_decode($gal_response, true);

// print nicely
print_r($gal_response_array);
//grab new gallery ID
$gal_ID=$gal_response_array["rsp"]["gallery"]["GID"];
}

function upload($img)
{
global $ID;
//global $gal_ID;
// required parameters for the OAuth-authentication
// replace all parameters!
$API_key = "ABCD1234";
$API_secret = "ABCD1234";
$on1=rand(10000000,99999999);
$oauth_nonce = "$on1";
$oauth_token = "ABCD1234";
$oauth_token_secret = "ABCD1234";
$oauth_timestamp = time();
$oauth_signature_method = "MD5";

// build the signature string
$oauth_signature_string = "";
$oauth_signature_string .= $API_key;
$oauth_signature_string .= $API_secret;
$oauth_signature_string .= $oauth_timestamp;
$oauth_signature_string .= $oauth_nonce;
$oauth_signature_string .= $oauth_token;
$oauth_signature_string .= $oauth_token_secret;

// calculate the MD5-checksum of the signature string
$oauth_signature = md5($oauth_signature_string);

// populate an array with parameters
$pvars   = array(
        // parameters required by OAuth
        "oauth_consumer_key" => $API_key,
        "oauth_signature_method" => $oauth_signature_method,
        "oauth_signature" => $oauth_signature,
        "oauth_timestamp" => $oauth_timestamp,
        "oauth_nonce" => $oauth_nonce,
        "oauth_token" => $oauth_token,

        // optional parameters
        "content_type" => "adult",
        "thumb_size" => "180x180",
        "image" => "@$img", // ATTENTION - note the @ infront of the filename!
        "gallery_id" => "$ID"
);
//print_r($pvars);
// initialize curl and set parameters
$curl    = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.imagebam.com/sys/API/resource/upload_image');
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

// execute, get information and close connection
$response = curl_exec($curl);
$info = curl_getinfo($curl);
curl_close ($curl);

// decode the json-encoded response
$response_array = json_decode($response);

// print nicely
print_r($response_array);
print_r($info);
}

//gallery($argv[1]);
$dir=$argv[2];

foreach(scandir("$dir") as $entry)
{
 if ($entry != "." && $entry != ".." && $entry != "upload_folder.php")
 {
  upload("$dir$entry");
 }
}

?>
From pixhosts api docs - https://pixhost.to/api/index.html#galleries

Code:
{   "gallery_name": "Test gallery",   "gallery_hash": "8NtKF",   "gallery_url": "http:\/\/pixhost.to\/galleries\/8NtKF",   "gallery_upload_hash": "yKtOl8NbHMYJ8yWj8Mh90sIlfXC7PXT6RHW8Xua7" }
Another note, I chose to use PHP for these operations because it can natively turn json into objects.

You get the response back from the API in json format, and using json_decode function in PHP you could get rid of all of the sed calls you make to pull out the image link. With php it would come back from the curl call as a reponse ($curl_response)

Then just json decode and you would have an object you could call

Code:
$resp=json_decode($response);
$imglink=$resp->show_url;
__________________
My posts are scripted, sorry if the preview images aren't great, but the whole gallery is in the link
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


If I post any duplicates, please PM me and I will remove them

Last edited by herkalurk; June 17th, 2017 at 05:11 PM..
herkalurk is offline   Reply With Quote
The Following 7 Users Say Thank You to herkalurk For This Useful Post: