Garmin API中的OAuth标题错误



使用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();
});

我发现了以下解决方案来解决此问题:

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

相关内容

  • 没有找到相关文章

最新更新