0

我通过 OVH 的 API 开发域管理软件。我使用nodejsnode-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 的模块源,如果签名在散列之前和之后是正确的,但这一切似乎都很好......

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

4

1 回答 1

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);
})

无论如何,它无法正常工作,请告诉我们您遇到的错误。

于 2016-06-14T12:55:14.090 回答