通过url连接,testMe函数给出错误,没有欢迎消息

时间:2016-06-14 12:32:09

标签: javascript node.js api node-webkit ovh

我通过OVH的API处理域管理软件。 我使用 nodejs node-webkit ,然后我下载了OVH的官方 Node.js 包装器。

然后,我按照此处的文档:https://www.npmjs.com/package/ovh和此处:https://eu.api.ovh.com/g934.first_step_with_api,我提供了以下代码:

// set the ovh object with the right configuration
var ovh = require('ovh')({
  endpoint: 'ovh-eu',
  appKey: 'APP_KEY', // replace it with my key
  appSecret: 'APP_SECRET' // replace it with my key
});

ovh.request('POST', '/auth/credential', {
  // set access rules
  'accessRules': [
    {'method': 'GET', 'path': '/*'},
    {'method': 'POST', 'path': '/*'},
    {'method': 'PUT', 'path': '/*'},
    {'method': 'DELETE', 'path': '/*'},
  ]
}, function (error, credential) {
  // print the error if the request failed, else, print the response
  console.log(error || credential);
  // set the consumerKey in the ovh object
  ovh.consumerKey = credential.consumerKey;
  // connect on the credential.validationUrl to validate the consumerKey
  console.log(credential.validationUrl);

  testMe();
});


function testMe() {
  /*
    This fonction test a request every second
    to check if the user connected himself
  */
  ovh.requestPromised('GET', '/me')

    .then (function (me) {
      // if the user is connected, tell him welcome
      console.log('Welcome ' + me.firstname);
    }
  )
    .catch (function (err) {
      console.log(err);
      // while the user is not connected, retry the request
      setTimeout(testMe, 1000);
    }
  );
}

好吧,当我执行此操作时,一切正常,直到我尝试通过URL连接,testMe函数一直告诉我错误,我没有得到欢迎消息。

为了解决我的问题,我尝试使用不同的方式编写我的代码,甚至在OVH的模块源中检查签名是否正好在散列之前和之后,但这一切似乎都很好......

如果某人已经遇到此问题,或者有人在我的代码中发现错误,我将非常感谢您的帮助。感谢

1 个答案:

答案 0 :(得分:0)

您遇到语法错误:

then (function (response) {
      // if the user is connected, tell him welcome
      console.log('Welcome ' + me.firstname);
})

尝试这样做(重命名参数):

then (function (me) {
      // if the user is connected, tell him welcome
      console.log('Welcome ' + me.firstname);
})

无论如何,它不能正常工作请告诉我们你得到的错误。