A Fanfou API library for Go
- Simple and intuitive endponits and error wrapping
- Struct and original JSON output
- Supports OAuth (safer) and XAuth (simpler)
- Covers all endpoints of Fanfou API v1 over HTTPS
$ go get -u github.com/mogita/go-fanfou
package main
import "github.com/mogita/go-fanfou/fanfou"
func main() {
// ...
}
To call an endpoint e.g. /statuses/public_timeline
, you can call it like this:
// Every API endpoint has the same return value structure
data, JSON, err := c.Statuses.PublicTimeline(&fanfou.StatusesOptParams{
Count: 10,
})
All optional parameter types starts with the resource's name. E.g. Statuses
-> StatusesOptParams
.
See the examples
directory to learn how to authenticate the client instance before calling the endpoints.
Errors default to the format as below:
POST http://api.fanfou.com/photos/upload.json: 400 上传照片失败
Meanwhile they can be asserted to extract the specific detail that you can use to handle the errors programmatically. Like this:
_, _, err := c.Statuses.PublicTimeline(nil)
if err != nil {
if fanfouErr, ok := err.(*fanfou.ErrorResponse); ok {
// Will print only the error message text returned by Fanfou API
fmt.Printf("%s\n", fanfouErr.GetFanfouError())
return
}
// Will print the default error format
fmt.Println(err)
return
}
Check out the examples
folder for working code snippets. You can run the examples with these commands to see how this library works:
$ go run examples/oauth/oauth.go --consumerkey <your_consumer_key> --consumersecret <your_consumer_secret>
OOB stands for "out of band"
$ go run examples/oauth_oob/oauth_oob.go --consumerkey <your_consumer_key> --consumersecret <your_consumer_secret>
$ go run examples/xauth/xauth.go --consumerkey <your_consumer_key> --consumersecret <your_consumer_secret> --username <your_username> --password <your_password>
$ go run examples/upload_photo/upload_photo.go --consumerkey <your_consumer_key> --consumersecret <your_consumer_secret> --username <your_username> --password <your_password>
- oauth (a fork of mrjones/oauth) - OAuth 1.0 implementation in go (golang)
- go-github - This library mimics its structure. A copy of its LICENSE can be found here go-github-LICENSE
Thank you very much for paying attention to this library. If you feel like helping improve it, please kindly make sure to follow the instructions:
Link the pre-commit hook which runs tests and go-fmt before committing
ln -s $PWD/pre-commit.sh .git/hooks/pre-commit
Always run tests before committing
go test ./...
You can also follow this Trello board if you're interested in the progress of this project and its sibling products.
MIT © mogita