modulepackage
0.1.0
Repository: https://github.com/haozibi/fanfou-sdk-golang.git
Documentation: pkg.go.dev
# README
fanfou-sdk-golang
Fanfou SDK for Golang
Features
- Simple API and Error wrapping
- Supports OAuth and XAuth
- Use secure HTTPS protocol
Installation
$ go get -u github.com/haozibi/fanfou-sdk-golang
Example
Use Environment FANFOU_SDK_DEBUG
to enable debug mode:
$ FANFOU_SDK_DEBUG=true go run examples/status/main.go
OAuth Authentication
$ go run example/oauth/main.go\
-consumerKey <consumerKey>\
-consumerSecret <consumerSecret>
OAuth oob Authentication
$ go run example/oauth_oob/main.go\
-consumerKey <consumerKey>\
-consumerSecret <consumerSecret>
Send Status With XAuth Authentication
$ go run examples/status/main.go \
-consumerKey <consumerKey>\
-consumerSecret <consumerSecret>\
-password <password>\
-username <username>\
-status "在这里,无人知晓你是谁"
Send Picture Status With XAuth Authentication
$ go run examples/status/main.go \
-consumerKey <consumerKey>\
-consumerSecret <consumerSecret>\
-password <password>\
-username <username>\
-status "在这里,无人知晓你是谁"\
-picture https://i.loli.net/2019/12/12/gYRoF4exsyNCc5J.jpg
PublicTimeline With XAuth
$ go run examples/status/main.go \
-consumerKey <consumerKey>\
-consumerSecret <consumerSecret>\
-password <password>\
-username <username>
More Example Example
Error Handling
- All Error Wrap By "github.com/pkg/errors"
- API Response Error use
ErrorResponse
struct
import pkgErr "github.com/pkg/errors"
func TestError(t *testing.T) {
var f fanfou.Fanfou
_, err := f.AccountService.VerifyCredentials(context.Background())
if err != nil {
err = pkgErr.Cause(err)
var e *utils.ErrorResponse
if errors.As(err, &e) {
fmt.Println(e.GetStatusCode())
fmt.Println(e.GetErrorMsg())
fmt.Println(e.GetRequest())
} else {
fmt.Println(e)
}
}
}
Important
- Do not support callback
- Only API v1
License
MIT