好吧,我似乎无法弄清楚为什么我的函数没有在点击或加载时定义。
我已经通过 firebug 运行它,并且看不到任何语法错误。任何帮助,将不胜感激。
小提琴:http: //jsfiddle.net/170a71mj/1/
有问题的代码:
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;
}