b2.authorizationToken is null
LovikaJain opened this issue · 3 comments
Hi I am trying to use backblaze-b2 plugin in my application but when I used b2.authorize() I am getting this error : Error: Invalid authorizationToken
I debugged it and found that b2.authorizationToken is null in utils.js
Could somebody tell me what could have went wrong?
Code :
var B2 = require('backblaze-b2');
// create B2
// create b2 object instance
var b2 = new B2({
accountId: 'accId',
applicationKey: 'appkey'
});
b2.authorize();
@LovikaJain you might have to call the authorization method INSIDE whatever other call you are trying to do, in order for it to work. I am having no issues in my project doing it this way.
E.g. (as in the README):
async function GetBuckets() {
try {
await b2.authorize();
var response = await b2.listBuckets()
console.log(response.data)
} catch (e){
console.log('Error getting buckets:', e)
}
}
Also note that b2.authorize()
returns a promise, meaning that if you do not await
the promise before making your next request, you have a race condition.
Yep - you'll have to await the promise returned by b2.authorize()
before calling any other methods. If there's still an error after that it's likely that you've entered your credentials incorrectly. If you're still having this issue please reopen. :)