dropbox

package module
v0.0.0-...-b8f725d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2016 License: MIT Imports: 14 Imported by: 0

README

= Dropbox SDK for Go [UNOFFICIAL]

An **UNOFFICIAL** Go SDK for integrating with the Dropbox API v2. Tested with Go 1.5+

WARNING: This SDK is **NOT yet official**. What does this mean?

  * There is no formal Dropbox https://www.dropbox.com/developers/support[support] for this SDK at this point
  * Bugs may or may not get fixed
  * Not all SDK features may be implemented and implemented features may be buggy or incorrect
  

=== Uh OK, so why are you releasing this?

  * the SDK, while unofficial, _is_ usable. See https://github.com/dropbox/dbxcli[dbxcli] for an example application built using the SDK
  * we would like to get feedback from the community and evaluate the level of interest/enthusiasm before investing into official supporting one more SDK
 
== Installation

[source,sh]
----
$ go get github.com/dropbox/dropbox-sdk-go-unofficial
----

Note that while the import path ends in `dropbox-sdk-go-unofficial`, it actually exports the package `dropbox`. There are additional subpackages, one for each namespace in the https://www.dropbox.com/developers/documentation/http/documentation[API]:

  * `github.com/dropbox/dropbox-sdk-go-unofficial/users`
  * `github.com/dropbox/dropbox-sdk-go-unofficial/files`
  * `github.com/dropbox/dropbox-sdk-go-unofficial/sharing`
  * `github.com/dropbox/dropbox-sdk-go-unofficial/team`

== Usage

First, you need to https://dropbox.com/developers/apps:[register a new "app"] to start making API requests. Once you have created an app, you can either use the SDK via an access token (useful for testing) or via the regular OAuth2 flow (recommended for production).

=== Using OAuth token

Once you've created an app, you can get an access token from the app's console. Note that this token will only work for the Dropbox account the token is associated with.

[source,go]
----
// NOTE: this imports package `dropbox`
import "github.com/dropbox/dropbox-sdk-go-unofficial"

func main() {
  api := dropbox.Client(token, true) // second argument enables verbose logging in the SDK
  // start making API calls
}
----

=== Using OAuth2 flow

For this, you will need your `APP_KEY` and `APP_SECRET` from the developers console. Your app will then have to take users though the oauth flow, as part of which users will explicitly grant permissions to your app. At the end of this process, users will get a token that the app can then use for subsequent authentication. See https://godoc.org/golang.org/x/oauth2#example-Config[this] for an example of oauth2 flow in Go.

Once you have the token, usage is same as above.

=== Making API calls

Each Dropbox API takes in a request type and returns a response type. For instance, https://www.dropbox.com/developers/documentation/http/documentation#users-get_account[/users/get_account] takes as input a `GetAccountArg` and returns a `BasicAccount`. The typical pattern for making API calls is:

  * Instantiate the argument via the `New*` convenience functions in the SDK
  * Invoke the API
  * Process the response (or handle error, as below)
  
Here's an example:

[source, go]
----
  arg := users.NewGetAccountArg()
  if resp, err := api.GetAccount(arg); err != nil {
    return err
  }
  fmt.Printf("Name: %v", resp.Name)
----

=== Error Handling

As described in the https://www.dropbox.com/developers/documentation/http/documentation#error-handling[API docs], all HTTP errors _except_ 409 are returned as-is to the client (with a helpful text message where possible). In case of a 409, the SDK will return an endpoint-specific error as described in the API. This will be made available as `EndpointError` member in the error.

== Note on using the Teams API

All features of the Team API are supported except https://www.dropbox.com/developers/documentation/http/teams#teams-member-file-access[acting on behalf of team members]. This should be available soon.

Note that to use the Team API, you will need to create a Dropbox Business App. The OAuth token from this app will _only_ work for the Team API.

Please read the https://www.dropbox.com/developers/documentation/http/teams[API docs] carefully to appropriate secure your apps and tokens when using the Team API.

== Caveats

  * To re-iterate, this is an **UNOFFICIAL** SDK and thus has no official support from Dropbox
	* Only supports the v2 API. Parts of the v2 API are still in beta, and thus subject to change
	* This SDK itself is in beta, and so interfaces may change at any point

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OAuthEndpoint

func OAuthEndpoint(domain string) oauth2.Endpoint

OAuthEndpoint constructs an `oauth2.Endpoint` for the given domain

Types

type Api

type Api interface {
	files.Files
	sharing.Sharing
	team.Team
	users.Users
}

func Client

func Client(token string, options Options) Api

Client returns an `Api` instance for Dropbox using the given OAuth token.

type Options

type Options struct {
	Verbose    bool
	AsMemberId string
	Domain     string
}

Directories

Path Synopsis
This namespace contains endpoints and data types for basic file operations.
This namespace contains endpoints and data types for basic file operations.
This namespace contains endpoints and data types for creating and managing shared links and shared folders.
This namespace contains endpoints and data types for creating and managing shared links and shared folders.
This namespace contains endpoints and data types for user management.
This namespace contains endpoints and data types for user management.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL