Try using Dropbox API v2 with Go
As the title suggests, I tried using the Dropbox API.
Go get to get started
```
go get github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/...
```
Sample code for uploading files
It is a process of creating an instance and uploading a file.
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: "<Obtained access token>",
}
dbx := users.New(config)
req := files.NewCommitInfo("<File upload destination>")
f, _ := os.Open("<The path of the file you want to upload>")
_, err := dbx.Upload(req, f)
if err != nil {
log.Print(err)
return
}
}
Get an access token for the Dropbox API
I registered from the following site and got an access token.
https://www.dropbox.com/developers
I tried it, but ...
It didn't work.
I got the message
"missing_scope" and looked it up, but it wasn't authoritative.
I added
files.content.write to edit the contents of Dropbox files and folders, which has no permissions added by default, and ran it again and it worked.
Where I got stuck
Obviously, you will need to reissue the access token after adding permissions. Please be careful, too.
Impressions
I would like to create a system that saves the images sent to LINE Bot in Dropbox.