Try access gallery API from other project

Hi, I am trying access api from other web application (via javascript) but I have permission problems...

I can access a list using only Authentication Basic

But to generate as thumbs or view the image, I can not access. Returns {"message": "CSRF verification failed"}

I noticed that I need to enter a parametric "requesttoken"

My question is ... how to generate this token?

Thank you!

You can get the token with OC.requestToken in JS code

Need to make all my interactions through ajax.

I only have login and password
And Basic Authorization with btoa('login:password')