|
7 лет назад | |
---|---|---|
.. | ||
dropbox | 7 лет назад | |
generator | 7 лет назад | |
.gitignore | 7 лет назад | |
.gitmodules | 7 лет назад | |
.travis.yml | 7 лет назад | |
LICENSE | 7 лет назад | |
README.md | 7 лет назад |
An UNOFFICIAL Go SDK for integrating with the Dropbox API v2. Tested with Go 1.5+
:warning: WARNING: This SDK is NOT yet official. What does this mean?
$ go get github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/...
For most applications, you should just import the relevant namespace(s) only. The SDK exports the following sub-packages:
github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth
github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/files
github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/sharing
github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/team
github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/users
Additionally, the base github.com/dropbox/dropbox-sdk-go-unofficial/dropbox
package exports some configuration and helper methods.
First, you need to 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).
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.
import "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox"
import "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/users"
func main() {
config := dropbox.Config{Token: token, Verbose: true} // second arg enables verbose logging in the SDK
dbx := users.New(config)
// start making API calls
}
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 this for an example of oauth2 flow in Go.
Once you have the token, usage is same as above.
Each Dropbox API takes in a request type and returns a response type. For instance, /users/get_account takes as input a GetAccountArg
and returns a BasicAccount
. The typical pattern for making API calls is:
New*
convenience functions in the SDKHere's an example:
arg := users.NewGetAccountArg(accountId)
if resp, err := dbx.GetAccount(arg); err != nil {
return err
}
fmt.Printf("Name: %v", resp.Name)
As described in the 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.
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 API docs carefully to appropriate secure your apps and tokens when using the Team API.
This SDK is automatically generated using the public Dropbox API spec and Stone. See this README for more details on how code is generated.