简体   繁体   中英

ReferenceError: parameters is not defined in Ember.js

App.StaticConfig = Ember.Object.extend({
    URL: null,
    parameters: null,
    consumerSecret: null,
    encodedSignature: null,
    callback: null,
});


var staticConfig = App.StaticConfig.create({
    URL: 'https://api.twitter.com/oauth/request_token',
    parameters: {
        oauth_consumer_key : 'key',
        oauth_nonce : 'kllo9940pd9333jh',
        oauth_timestamp : '1191242096',
        oauth_signature_method : 'HMAC-SHA1',
        oauth_version : '1.0',
    },

    consumerSecret : 'key',
    encodedSignature : oauthSignature.generate('POST', URL, parameters, consumerSecret),

});

App.TwitterController = Ember.ObjectController.extend({

    actions: {  

        loginTwitter: function() {
            console.log('Event Clicked');
            return new Ember.RSVP.Promise(function(resolve, reject) {
            Ember.$.ajax({
                url:         'https://api.twitter.com/oauth/request_token',
                type:        'POST',
                contentType: "jsonp",
                headers: {
                    "Authorization": 'OAuth oauth_callback='+ staticConfig.get('callback') +', oauth_consumer_key="", oauth_nonce="kllo9940pd9333jh", oauth_signature='+ staticConfig.get('encodedSignature') +', oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_version="1.0"'
                },

                contentType: 'application/x-www-form-urlencoded'
            }).then(function(response) {
                console.log('Successed');
                console.log(response);
                resolve (response);
            }, function(xhr, status, error) {
                console.log(error);
                console.log('In Error');
                reject(error);
            });
        });
        },
    }
});

At below line I get ReferenceError: parameters is not defined and also same for consumerSecret encodedSignature : oauthSignature.generate('POST', URL, parameters, consumerSecret),

Also is my creating oauth_signature and oauth_nonce correctly.

Looks like encodedSignature can be nicely implemented as computed property:

encodedSignature : function () {
  var URL = this.get('URL');
  var parameters = this.get('parameters');
  var consumerSecret = this.get('consumerSecret');

  return oauthSignature.generate('POST', URL, parameters, consumerSecret)
}.property('URL', 'parameters', 'consumer_secret')

好吧,实际上,您的代码中没有设置parametersconsumerSecret :确实有您正在创建的对象的属性名称 ,而不是声明的变量。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM