2

使用 GArmin API 删除用户注册时出现错误

{ errorMessage: 'Unable to read oAuth header' }

我正在使用以下 API:-

https://healthapi.garmin.com/wellness-api/rest/user/registration

我的代码如下: -

restler.get(accessTokenUrl, {

    headers: {'Authorization': 'Bearer ACCESS_TOKEN'}

}).on('complete', function(data) {
  console.log(data);

  cb();
});
4

1 回答 1

0

我找到了以下解决方案来解决这个问题:

var backFillUrl = 'https://healthapi.garmin.com/wellness-api/rest/user/registration';
var newoauthTimeStamp = moment().unix();
var parameters = {
  oauth_consumer_key: config.garminHealth.consumer_key,
  oauth_nonce: oauthNonce,
  oauth_signature_method: oauthSignatureMethod,
  oauth_timestamp: newoauthTimeStamp,
  oauth_token: user.garmin.accessToken,
  oauth_version: oauthVersion      
};
var newAuthSignature = oauthSignature.generate('GET', backFillUrl, parameters, config.garminHealth.secret_key, user.garmin.accessTokenSecret, {encodeSignature: true});

var OAuthHeader = 'OAuth oauth_version="' + oauthVersion + '", oauth_consumer_key="' + config.garminHealth.consumer_key +
'", oauth_timestamp="' + newoauthTimeStamp + '", oauth_nonce="' + oauthNonce + '", oauth_signature_method="' +
oauthSignatureMethod + '", oauth_signature="' + newAuthSignature + '", oauth_token="' + user.garmin.accessToken + '"';

restler.get(backFillUrl, {
  query: {
    accessToken: 'ACCESS_TOKEN'
  },
  headers: {'Authorization': OAuthHeader}
}).on('complete', function (er) {
  if(er) return cb(er);
  else cb();
});
于 2018-06-13T05:51:54.367 回答