Javascript,未捕获引用错误:function()未定义

时间:2015-02-26 18:38:47

标签: javascript api rest twitter photobucket

好吧,我似乎无法弄清楚为什么我的函数没有在click或onload上定义。

我通过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;
    }

1 个答案:

答案 0 :(得分:0)

问题在于我包含的sha1实现。经过大量测试(逐行),删除包含它后,它就有效了。

由于