Comments (9)
I explained authentication in #36. If you don’t run your code as a Nextcloud app, you have to deal with authentication yourself in the xhrProvider. Just add a basic auth header.
Events you can add by calling “createVObject” on a calendar object. To get a complete API documentation, just run npm run build-doc
from cdav-library.
Hi georgehrke,
thank you for the prompt response,
I compiled and now can see the API.
I've also looked over the xhrProvider.
But I still don't see anywhere to put in my url, username, and password.
Would it be possible to make a basic "hello world" type application, that retrieves the calendar info from one of the demo instances of nextcloud?
A working example is worth a thousand words.
Thanks,
Logan
from cdav-library.
function xhrProvider() {
var headers = {
'X-Requested-With': 'XMLHttpRequest',
'requesttoken': OC.requestToken
}
var xhr = new XMLHttpRequest()
var oldOpen = xhr.open
// override open() method to add headers
xhr.open = function() {
var result = oldOpen.apply(this, arguments)
for (let name in headers) {
xhr.setRequestHeader(name, headers[name])
xhr.setRequestHeader('Authorization', 'Basic ' + btoa(unescape(encodeURIComponent(YOUR_USERNAME + ':' + YOUR_PASSWORD))))
}
return result
}
OC.registerXHRForErrorProcessing(xhr)
return xhr
}
const client = new DavClient({
rootUrl: OC.linkToRemote('dav')
}, xhrProvider)
await client.connect({enableCalDAV: true});
const calendars = await client.calendarHomes[0].findAllCalDAVCollections()
const events = await calendars[0].findAllVObjects()
console.log(events[0].data);
You can read more about Http auth here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#The_general_HTTP_authentication_framework
The URL of the server is given in rootUrl: OC.linkToRemote('dav')
. You have to replace that with your URL. Just point it to /remote.php/dav/
of your Nextcloud instance.
from cdav-library.
@elspru Did that answer your question? :)
from cdav-library.
Hi @georgehrke it does seem to be better, but I'm still not really sure how to use it.
Like I'm trying to use this for a node application, but it seems that the code you gave me is for a web browser, and I'm not sure how to require() stuff in it. like should I have a sample web page also or something?
Maybe If I explain my use case it will make more sense.
I started on a Telegram chat bot and want it to send me calendar notifications, and have event specific behaviour. Like if I'm hosting a meditation session, it can read the title to know that, and then it will ask me at the appropriate times stuff like "what is the head count?" and "how much was donated?", so that the bot can function as my secretary and put that into the csv files and generate the website accordingly so the community knows where we are at, and if we have enough donations to cover the year more or less in real time.
Basically I need a minimal use case example in node.
or if it is in browser, then the example would ideally also tell me how to include it in the web page.
I'm sorry that I don't know very much about how this library works. I'm used to npm installing things, and having like a straight forward require('library'); pull_database(url, username, password); style API.
from cdav-library.
I tried this:
<script src=cdav-library.js></script>
<script>
function xhrProvider() {
var headers = {
'X-Requested-With': 'XMLHttpRequest',
'requesttoken': OC.requestToken
}
var xhr = new XMLHttpRequest()
var oldOpen = xhr.open
// override open() method to add headers
xhr.open = function() {
var result = oldOpen.apply(this, arguments)
for (let name in headers) {
xhr.setRequestHeader(name, headers[name])
xhr.setRequestHeader('Authorization', 'Basic ' +
btoa(unescape(encodeURIComponent('logan' + ':' + 'mysecurepssword'))))
}
return result
}
OC.registerXHRForErrorProcessing(xhr)
return xhr
}
const client = new DavClient({
rootUrl: 'https://nc.liberit.ca', // OC.linkToRemote('dav')
}, xhrProvider)
async function init(){
await client.connect({enableCalDAV: true});
const calendars = await client.calendarHomes[0].findAllCalDAVCollections()
const events = await calendars[0].findAllVObjects()
console.log(events[0].data);
console.log('hello world');
}
</script>
<body onload="init()">
hello
</body>
It tells me DavClient is not defined.
from cdav-library.
Same here, no DavClient defined. There is 'cdav' but:
TypeError: cdav is not a constructor
I try to use with nextcloud.
from cdav-library.
I'm not sure if it will work when using <script src=cdav-library.js></script>
, because we use ES6 Modules
.
Please see https://hacks.mozilla.org/2015/08/es6-in-depth-modules/ how to use them.
But i would recommend to use web pack in the meantime, until all major browsers adapted ES6 Modules
.
An example how to use this library with web pack can be found in the contacts app.
from cdav-library.
Since there was no response or no further questions here for two months i will close this ticket.
from cdav-library.
Related Issues (20)
- Allow us to provide custom props on findAllAndFilterBySimpleProperties HOT 1
- General-purpose WebDAV library HOT 6
- How to create Event? HOT 1
- Need Help in addressbookQuery HOT 2
- Use shared browserslist config
- add If-None-Match: * header for creating events / vcards
- Make requests cancellable
- [Enhancement] Documentation on use would be wonderfully useful HOT 2
- Make a proper module of it? HOT 2
- Cannot read property 'length' of undefined HOT 5
- Versioning and publishing HOT 4
- Allow to fetch user principal language
- Wrong Content-Type request header in PUT requests HOT 4
- `npm run build-doc` throws an error HOT 1
- Rename master branch to main HOT 2
- Installing this via npm broken by one of the newer commits HOT 2
- Migrate Request class to @nextcloud/axios
- npm package is outdated
- propfind assumes DAV header always exists and causes null exception when missing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cdav-library.