Update README

This commit is contained in:
JBP
2019-08-18 23:59:33 +02:00
parent 84d4471770
commit 65570e9b25
+17 -14
View File
@@ -22,9 +22,10 @@ An example for the [client credentials grant flow](https://developer.ebay.com/ap
```go ```go
import ( import (
"context" "context"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials" "golang.org/x/oauth2/clientcredentials"
"github.com/jybp/ebay"
) )
func main() { func main() {
@@ -33,12 +34,13 @@ func main() {
ClientSecret: "your client secret", ClientSecret: "your client secret",
TokenURL: ebay.OAuth20SandboxEndpoint.TokenURL, TokenURL: ebay.OAuth20SandboxEndpoint.TokenURL,
Scopes: []string{ebay.ScopeRoot /* your scopes */}, Scopes: []string{ebay.ScopeRoot /* your scopes */},
} }
tc := oauth2.NewClient(context.Background(), ebay.TokenSource(cfg.TokenSource(ctx))) ctx := context.Background()
client := ebay.NewSandboxClient(tc) tc := oauth2.NewClient(ctx, ebay.TokenSource(cfg.TokenSource(ctx)))
client := ebay.NewSandboxClient(tc)
// Get an item detail. // Get an item detail.
result, err := client.Buy.Browse.GetItem(context.Background(), "v1|123456789012|0") result, err := client.Buy.Browse.GetItem(ctx, "v1|123456789012|0")
} }
``` ```
@@ -47,13 +49,13 @@ An example for the [authorization code grant flow](https://developer.ebay.com/ap
```go ```go
import ( import (
"context" "context"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials" "github.com/jybp/ebay"
) )
func main() { func main() {
cfg := oauth2.Config{ cfg := oauth2.Config{
ClientID: "your client id", ClientID: "your client id",
ClientSecret: "your client id", ClientSecret: "your client id",
Endpoint: ebay.OAuth20SandboxEndpoint, Endpoint: ebay.OAuth20SandboxEndpoint,
@@ -62,18 +64,19 @@ func main() {
} }
url := cfg.AuthCodeURL(state) url := cfg.AuthCodeURL(state)
fmt.Printf("Visit the URL: %v\n", url) fmt.Printf("Visit the URL: %v\n", url)
var authCode string /* Retrieve the authorization code. */ var authCode string /* Retrieve the authorization code. */
ctx := context.Background()
tok, err := oauthConf.Exchange(ctx, authCode) tok, err := oauthConf.Exchange(ctx, authCode)
if err != nil { if err != nil {
panic(err) panic(err)
} }
client := ebay.NewSandboxClient(oauth2.NewClient(ctx, ebay.TokenSource(cfg.TokenSource(ctx, tok)))) client := ebay.NewSandboxClient(oauth2.NewClient(ctx, ebay.TokenSource(cfg.TokenSource(ctx, tok))))
// Get bidding for the authenticated user. // Get bidding for the authenticated user.
bidding, err := client.Buy.Offer.GetBidding(ctx, "v1|123456789012|0", ebay.BuyMarketplaceUSA) bidding, err := client.Buy.Offer.GetBidding(ctx, "v1|123456789012|0", ebay.BuyMarketplaceUSA)
} }
``` ```