Skip to content

haozibi/fanfou-sdk-golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fanfou-sdk-golang

logo

CircleCI Coverage Status GoDoc pkg.go.dev Go Report Card

Fanfou SDK for Golang

README.md | 中文 README.md

Features

  • Simple API and Error wrapping
  • Supports OAuth and XAuth
  • Use secure HTTPS protocol

Fanfou API Docs

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