Well, I can't seem to figure out why my function is not defined on click, or onload.
I've ran it through firebug, and can't see any syntax errors. Any help would be appreciated.
Fiddle: http://jsfiddle.net/170a71mj/1/
The code in question:
function getAlbums(user, album) {
var url = "http://api.photobucket.com/album/";
url = url + encodeURIComponent( user + "/" + album )
var json = callPhotobucket( url, "format=json" );
}
function getTag(media) {
var url = "http://api.photobucket.com/media/";
url = url + encodeURIComponent(media) + "/tag" ;
var json = callPhotobucket(url, "format=json");
}
function getTimestamp() {
var timestamp = new Date().valueOf();
timestamp = timestamp / 1000;
timestamp = Math.ceil( timestamp );
return timestamp;
}
function ping() {
auth_url = callPhotobucket( "http://api.photobucket.com/ping", "format=json" );
}
function callPhotobucket( url, format ) {
try {
if( url == undefined ) {
url = "http://api.photobucket.com/ping";
}
if( format == undefined ) {
format = "format=json";
}
var timestamp = getTimestamp();
auth_nonce="nonce" + timestamp;
auth_method = "HMAC-SHA1";
auth_timestamp = "" + timestamp;
auth_version="1.0";
auth_consumer = "&oauth_consumer_key="+ encodeURIComponent( consumer_key );
nonce = "&oauth_nonce="+ encodeURIComponent( auth_nonce );
auth_sig_method = "&oauth_signature_method="+ encodeURIComponent( auth_method );
auth_timestamp = "&oauth_timestamp="+ encodeURIComponent( auth_timestamp );
version = "&oauth_version=" + encodeURIComponent( auth_version );
paramstring = format + auth_consumer + nonce + auth_sig_method + auth_timestamp + version;
method = "GET";
base = encodeURIComponent( method ) + "&" + encodeURIComponent( url ) + "&" + encodeURIComponent( paramstring );
sig_hash = getSignature( consumer_secret+"&", base );
auth_sign = "&oauth_signature=" + sig_hash;
auth_url = url + "?" + paramstring + "&" + auth_sign;
myalert( ""+ auth_url+"");
return auth_url;
}
catch (err) {
alert( "Error " + err );
}
}
function getSignature(key, baseString) {
b64pad = '=';
var signature = b64_hmac_sha1(key, baseString);
return signature;
}
The problem was with the sha1 implementation I included. After much testing (line by line), when removing the include it worked.
Thanks