cURL error on login
Promethean
Registered Users Posts: 2 Beginner grinner
I've had a PHP script uses XML-RPC to pull a random image URL from a specified gallery. It's been running without any issues for several months now. It was adapted from sdmeyer's script I found on the forum.
Since 9/16 the script has been failing. After debugging, it appears that login fails with the message
Fault: Code: 8 Reason: CURL error: SSL certificate problem, verify that the CA cert is OK
I guess cURL figures into all this somehow.
Any help or insight into making this work would be appreciated. Thanks.
[php]
/* Adapted from sdmeyer's script */
/* First include xmlrpc.inc from http://phpxmlrpc.sourceforge.net/ in the directory where the script is located */
include("xmlrpc.inc");
/******************************CONFIG SECTION******************************/
// Logon name for the Smugmug account
$nick = 'nick';
// Password for Smugmug account
$password = 'password';
/*
** Smugmug server software version.
** Always check https://www.smugmug.com/hack/method-smugmug.login.withPassword to obtain latest version number
** Smugmug changes this number from time to time
** Avoid using Beta version numbers
*/
$version = '1.1.0';
/*
** API Key. Needs to be requested from smugmug.
** Script will fail without this.
*/
$apikey = 'apikey';
/*
** Change Album ID if you want a different folder to be used for random image pick.
** This is the number from the URL in your browser address bar when you open a gallery
** It would be elegant to get a list of albums, parse it for the title of the gallery you want to use.
** This would just cause an extra call to the smugmug server resulting in longer load time.
*/
$albumid = 'albumid';
/*
** Set size_image to any of the following values to generate the type of URL you want
** 'L' = Large Image
** 'O' = Original Image
** 'M' = Medium Image
** 'S' = Small Image
** 'Ti'= Tiny Image
** 'Th'= Thumbnail Image
*/
$size_image = 'L';
$debugOn = 0;
/******************************MAIN******************************/
/*
** Contact the smugmug server on the HTTPS port and turn off the debug messages for the script.
*/
$xmlrpc_client = new xmlrpc_client("/hack/xmlrpc/", "api.SmugMug.com", "443");
$xmlrpc_client->setDebug($debugOn);
// Create logon credentials.
$login_struct = array(
new xmlrpcval($nick, "string"),
new xmlrpcval($password,"string"),
new xmlrpcval($version, "string"),
new xmlrpcval($apikey,"string"));
// Logon to the server using HTTPS
$get_login_msg = new xmlrpcmsg('smugmug.login.withPassword', $login_struct);
$login_response = $xmlrpc_client->send($get_login_msg, '0', 'https');
$login_response_value = $login_response->value();
// Get SessionID from Smugmug and save it
$login_array = xmlrpc_decode($login_response_value);
$sessionid = $login_array;
// Determine if logged in or not
if (!$login_response->faultCode()) {
// print "Logged into Smugmug account";
} else {
print "Fault: ";
print "Code: " . $login_response->faultCode() . " Reason: " .$login_response->faultString()." ";
return 0;
}
// Get list of images
$images = getImageIDs($xmlrpc_client, $sessionid, $albumid);
$imageids = array_merge($images, $imageids);
reset($imageids);
/*
** Lists out all image urls in the album. We don't need this now so turned it off.
** Added for debuging purposes
*/
/*
while (list($key, $val) = each($imageids)) {
print "http://$nick.smugmug.com/photos/$val-$size_image.jpg
";
}
*/
// Generate Random URL and print it
list($key, $val) = each($imageids);
$rand_keys = array_rand($imageids);
$rand_image_id = $imageids[$rand_keys];
$rand_image_url = "http://$nick.smugmug.com/photos/$rand_image_id-$size_image.jpg";
echo "
";
$logout_struct = array(new xmlrpcval($sessionid, "string"));
$logout_msg = new xmlrpcmsg('smugmug.logout', $logout_struct);
$logout_response = $xmlrpc_client->send($logout_msg, '0', 'https');
if (!$logout_response->faultCode()) {
// Prints a debug message. Turn the print on just to see the path the code takes
// print "Logged out of Smugmug account";
} else {
print "Fault: ";
print "Code: " . $logout_response->faultCode() . " Reason: " .$logout_response->faultString()." ";
return 0;
}
/* getImageIDs: Returns Array $images */
function getImageIDs($xmlrpc_client, $sessionid, $albumid) {
$images_struct = array(new xmlrpcval($sessionid, "string"),new xmlrpcval($albumid, "string"));
$get_images_msg = new xmlrpcmsg('smugmug.images.get', $images_struct);
$get_images_response = $xmlrpc_client->send($get_images_msg, '0', 'https');
if (!$get_images_response) { die("getImages failed"); }
$get_images_value = $get_images_response->value();
if (!$get_images_response->faultCode()) {
return $images = php_xmlrpc_decode($get_images_value);
} else {
print "Fault: ";
print "Code: " . $get_images_response->faultCode() . " Reason: " .$get_images_response->faultString()."
";
return 0;
}
}
?>
[/php]
Since 9/16 the script has been failing. After debugging, it appears that login fails with the message
Fault: Code: 8 Reason: CURL error: SSL certificate problem, verify that the CA cert is OK
I guess cURL figures into all this somehow.
Any help or insight into making this work would be appreciated. Thanks.
[php]
/* Adapted from sdmeyer's script */
/* First include xmlrpc.inc from http://phpxmlrpc.sourceforge.net/ in the directory where the script is located */
include("xmlrpc.inc");
/******************************CONFIG SECTION******************************/
// Logon name for the Smugmug account
$nick = 'nick';
// Password for Smugmug account
$password = 'password';
/*
** Smugmug server software version.
** Always check https://www.smugmug.com/hack/method-smugmug.login.withPassword to obtain latest version number
** Smugmug changes this number from time to time
** Avoid using Beta version numbers
*/
$version = '1.1.0';
/*
** API Key. Needs to be requested from smugmug.
** Script will fail without this.
*/
$apikey = 'apikey';
/*
** Change Album ID if you want a different folder to be used for random image pick.
** This is the number from the URL in your browser address bar when you open a gallery
** It would be elegant to get a list of albums, parse it for the title of the gallery you want to use.
** This would just cause an extra call to the smugmug server resulting in longer load time.
*/
$albumid = 'albumid';
/*
** Set size_image to any of the following values to generate the type of URL you want
** 'L' = Large Image
** 'O' = Original Image
** 'M' = Medium Image
** 'S' = Small Image
** 'Ti'= Tiny Image
** 'Th'= Thumbnail Image
*/
$size_image = 'L';
$debugOn = 0;
/******************************MAIN******************************/
/*
** Contact the smugmug server on the HTTPS port and turn off the debug messages for the script.
*/
$xmlrpc_client = new xmlrpc_client("/hack/xmlrpc/", "api.SmugMug.com", "443");
$xmlrpc_client->setDebug($debugOn);
// Create logon credentials.
$login_struct = array(
new xmlrpcval($nick, "string"),
new xmlrpcval($password,"string"),
new xmlrpcval($version, "string"),
new xmlrpcval($apikey,"string"));
// Logon to the server using HTTPS
$get_login_msg = new xmlrpcmsg('smugmug.login.withPassword', $login_struct);
$login_response = $xmlrpc_client->send($get_login_msg, '0', 'https');
$login_response_value = $login_response->value();
// Get SessionID from Smugmug and save it
$login_array = xmlrpc_decode($login_response_value);
$sessionid = $login_array;
// Determine if logged in or not
if (!$login_response->faultCode()) {
// print "Logged into Smugmug account";
} else {
print "Fault: ";
print "Code: " . $login_response->faultCode() . " Reason: " .$login_response->faultString()." ";
return 0;
}
// Get list of images
$images = getImageIDs($xmlrpc_client, $sessionid, $albumid);
$imageids = array_merge($images, $imageids);
reset($imageids);
/*
** Lists out all image urls in the album. We don't need this now so turned it off.
** Added for debuging purposes
*/
/*
while (list($key, $val) = each($imageids)) {
print "http://$nick.smugmug.com/photos/$val-$size_image.jpg
";
}
*/
// Generate Random URL and print it
list($key, $val) = each($imageids);
$rand_keys = array_rand($imageids);
$rand_image_id = $imageids[$rand_keys];
$rand_image_url = "http://$nick.smugmug.com/photos/$rand_image_id-$size_image.jpg";
echo "
";
$logout_struct = array(new xmlrpcval($sessionid, "string"));
$logout_msg = new xmlrpcmsg('smugmug.logout', $logout_struct);
$logout_response = $xmlrpc_client->send($logout_msg, '0', 'https');
if (!$logout_response->faultCode()) {
// Prints a debug message. Turn the print on just to see the path the code takes
// print "Logged out of Smugmug account";
} else {
print "Fault: ";
print "Code: " . $logout_response->faultCode() . " Reason: " .$logout_response->faultString()." ";
return 0;
}
/* getImageIDs: Returns Array $images */
function getImageIDs($xmlrpc_client, $sessionid, $albumid) {
$images_struct = array(new xmlrpcval($sessionid, "string"),new xmlrpcval($albumid, "string"));
$get_images_msg = new xmlrpcmsg('smugmug.images.get', $images_struct);
$get_images_response = $xmlrpc_client->send($get_images_msg, '0', 'https');
if (!$get_images_response) { die("getImages failed"); }
$get_images_value = $get_images_response->value();
if (!$get_images_response->faultCode()) {
return $images = php_xmlrpc_decode($get_images_value);
} else {
print "Fault: ";
print "Code: " . $get_images_response->faultCode() . " Reason: " .$get_images_response->faultString()."
";
return 0;
}
}
?>
[/php]
0
Comments
I'm no php coder, but I have a bit of experience with the SM xml-rpc api in javascript.
Try changing these to lines...
$xmlrpc_client = new xmlrpc_client("https://api.SmugMug.com/hack/xmlrpc/");
$login_response = $xmlrpc_client->send($get_login_msg);
Cheers,
David
SmugMug API Developer
My Photos
I've just got the logon working by using the cURL library to construct and send the XML login request. I get back the SessionID, UserID and the PasswordHash. It looks like some major script surgery may be in order.