Official Metrafin API Client for Node.js
GitHub | NPM | Official API Documentation
npm i metrafin
const App = require('metrafin')
Create an application with its private token.
const myApp = new App('VLeIjSNigss5eqLcNf5Snv2kh_d-HWOv1-ojr952gpW0CyKt')
// in async context
const userInfoA = await myApp.resolveUser('username', 'ethan')
// => { error: null, userId: '9175009b-b215-4be8-a3a8-88322757804d', username: 'ethan' }
// or...
const userInfoB = await myApp.resolveUser('userId', '9175009b-b215-4be8-a3a8-88322757804d')
// => { error: null, userId: '9175009b-b215-4be8-a3a8-88322757804d', username: 'ethan' }
Create an auth instance using an authorization_code
. You may access the accessToken as a property of the created authorization if all is successful.
It is recommended that you check that all of the OAuth scopes you expect are present in the auth instance's scopes
array.
const auth = await myApp.auth('rmxQPAll1kEhsc8u-IPwBkwyNdixJCSf', 'authorizationCode')
console.log('Auth accessToken: ' + auth.accessToken)
console.log('Auth userId: ' + auth.userId)
console.log('Auth scopes: ' + auth.scopes)
console.log('Auth expires: ' + auth.expires)
Create an auth instance using an access token
.
const auth = await myApp.auth('rmxQPAll1kEhsc8u-IPwBkwyNdixJCSf', 'accessToken')
console.log('Auth accessToken: ' + auth.accessToken)
console.log('Auth userId: ' + auth.userId)
console.log('Auth scopes: ' + auth.scopes)
console.log('Auth expires: ' + auth.expires)
See profile information documentation for details about the profile response.
await auth.getProfile()
See permissions documentation for details about the permissions response.
await auth.getPermissions()
See HonorScore documentation for details about the HonorScore response.
await auth.getHonorScore()
See reputation event documentation for details about reputation events.
await auth.createReputationEvent({
'context': 'public_comment',
'tag': 'spam',
'type': 'negative',
'description': 'Excessive commenting on a video'
})
// => {"error": null, "eventId": "0f6ca352-480a-468d-a99f-43580ccf4aff"}
await auth.getReputationEvents()
// => {"error": null, "reputationEvents": [ ... ]}
await auth.setReputationEventActive('ef8c4ce3-2f02-4647-ab5e-727387184e15', false)
// This will deactivate the reputation event with ID ef8c4ce3-2f02-4647-ab5e-727387184e15.
If you have questions or feedback about the package, feel free to let us know in GitHub issues.
Feel free to contribute through PRs as well. :)