File: README.md

package info (click to toggle)
golang-github-stacktic-dropbox 0.0~git20160424.0.58f839b-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 184 kB
  • ctags: 262
  • sloc: makefile: 2
file content (79 lines) | stat: -rw-r--r-- 2,287 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
dropbox
=======
Go client library for the Dropbox core and Datastore API with support for uploading and downloading encrypted files.

Support of the Datastore API should be considered as a beta version.

Prerequisite
------------
To use this library, you must have a valid client ID (app key) and client secret (app secret) provided by Dropbox.<br>
To register a new client application, please visit https://www.dropbox.com/developers/apps/create

Installation
------------
This library depends on the oauth2 package, it can be installed with the go get command:

    $ go get golang.org/x/oauth2

This package can be installed with the go get command:

    $ go get github.com/stacktic/dropbox


Examples
--------
This simple 4-step example will show you how to create a folder:

    package main

    import (
        "dropbox"
        "fmt"
    )

    func main() {
        var err error
        var db *dropbox.Dropbox

        var clientid, clientsecret string
        var token string

        clientid = "xxxxx"
        clientsecret = "yyyyy"
        token = "zzzz"

        // 1. Create a new dropbox object.
        db = dropbox.NewDropbox()

        // 2. Provide your clientid and clientsecret (see prerequisite).
        db.SetAppInfo(clientid, clientsecret)

        // 3. Provide the user token.
        db.SetAccessToken(token)

        // 4. Send your commands.
        // In this example, you will create a new folder named "demo".
        folder := "demo"
        if _, err = db.CreateFolder(folder); err != nil {
            fmt.Printf("Error creating folder %s: %s\n", folder, err)
        } else {
            fmt.Printf("Folder %s successfully created\n", folder)
        }
    }

If you do not know the user token, you can replace step 3 by a call to the Auth method:

        // This method will ask the user to visit an URL and paste the generated code.
        if err = db.Auth(); err != nil {
            fmt.Println(err)
            return
        }
        // You can now retrieve the token if you want.
        token = db.AccessToken()

If you want a more complete example, please check the following project: https://github.com/stacktic/dbox.

Documentation
-------------

API documentation can be found here: http://godoc.org/github.com/stacktic/dropbox.