I found out It seems that there are two way availalbe. Which of the following methods is correct?

  1. androidpublisher.NewService(ctx, option.WithHTTPClient(...))
func (_this *Factory) AccessToGoogle() (fac *Factory) {

    ctx := context.Background()
    jsonKey, err := ioutil.ReadFile(fac.property.GoogleAPIKey)
    if err != nil {
        fmt.Println("Can't read the API Key file")
        return
    }

    config, err := google.JWTConfigFromJSON(jsonKey, androidpublisher.AndroidpublisherScope)
    if err != nil {
        fmt.Println("Can't get jwt config")
        return
    }

    client := config.Client(ctx)

    GoogleAPI, err := androidpublisher.NewService(ctx, option.WithHTTPClient(client))
    if err != nil {
        fmt.Println("Can't androidpublisher service")
        return
    }

    fac.GoogleAPI = GoogleAPI

    return fac
}
  1. androidpublisher.NewService(ctx, option.WithCredentialsFile(...)
func (_this *Factory) AccessToGoogle() (fac *Factory) {

    ctx := context.Background()

    
    GoogleAPI, err := androidpublisher.NewService(ctx, option.WithCredentialsFile(GoogleAPIKey)
    if err != nil {
        fmt.Println("Can't androidpublisher service")
        return
    }

    fac.GoogleAPI = GoogleAPI

    return fac
}

To creat JWT is necessary? or just using the option.WithHTTPClient without creating jwtconfig is ok?

0

There are 0 best solutions below