I'm writing a little program using the dropbox api to learn go. I'm using the client library here: https://github.com/stacktic/dropbox.
I'm able to upload and download a file so I know my api keys and what not are working correctly. Using the Metadata method I can get the metadata for a file. However, when I try to use the UnmarshalJSON method to get a human readable date from the ClientMtime item in the entry struct, I get "unexpected end of JSON input". Any ideas on what's the issue?
The code I'm using is as follows:
func main() {
db := dropbox.NewDropbox()
db.SetAppInfo("Blah", "blah")
db.SetAccessToken("Token")
list,err := db.Metadata("/app_folder/test.jpg", true, false, "", "", 1)
if err != nil {
log.Fatal(err)
}
var date []byte
err = list.ClientMtime.UnmarshalJSON(date)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%v", date)
}
Thanks!
You want:
date, err := list.ClientMtime.MarshalJSON()
UnmarshalJson
goes the other way; []byte -> DBTime
That's why it's an end of input error, the []byte
is empty.
Optionally, ClientMTime
is a time. Time which has String()
and Format()
methods.
You can access all the time formatting features by converting it.
See: https://github.com/stacktic/dropbox/blob/master/dropbox.go#L158