Giter Club home page Giter Club logo

Comments (2)

ncalteen avatar ncalteen commented on September 2, 2024

Hello!

Unfortunately we do not have a Java 8-compatible JAR at this time. I will bring this up to the Engineering team to take a look at! In the meantime, you can continue to use the Google Wallet API, however you will need to instead build the API requests as JSON strings instead of using the object types defined by the library. An example can be found below:

HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
HttpRequestFactory httpRequestFactory = httpTransport.createRequestFactory();

GenericUrl objectUrl = new GenericUrl(String.format("https://walletobjects.googleapis.com/walletobjects/v1/genericObject/%s.%s", issuerId, objectSuffix));

// Build a payload for an object
// Make sure to include all required properties
// for this object type
String objectPayload = String.format(
    "{"
  + "  \"id\": \"%s.%s\","
  + "  \"classId\": \"%s.%s\""
  + "}",
  issuerId, objectSuffix, issuerId, classSuffix);

// Check if the object exists already
// Build a GET request
HttpRequest objectRequest = httpRequestFactory.buildGetRequest(objectUrl);

// Add auth to the request headers
objectRequest
    .setHeaders(new HttpHeaders()
        .setAuthorization("Bearer " + credentials.getAccessToken().getTokenValue()));

// Invoke the GET request
HttpResponse objectResponse = objectRequest.execute();

if (objectResponse.getStatusCode() == 404) {
  // Object does not yet exist
  // Send POST request to create it
  // Include the JSON payload
  objectRequest = httpRequestFactory.buildPostRequest(
      objectUrl,
      new JsonHttpContent(new GsonFactory(), objectPayload));

  // Add auth to the request
  objectRequest
      .setHeaders(new HttpHeaders()
          .setAuthorization("Bearer " + credentials.getAccessToken().getTokenValue()));

  // Invoke the POST request
  objectResponse = objectRequest.execute();
}

System.out.println("object GET or POST response: " + objectResponse.parseAsString());

Additional examples can be found in this repo in earlier commits (before we updated it to use the Walletobjects library). Check out this link for instance.

I hope this helps!

from rest-samples.

ncalteen avatar ncalteen commented on September 2, 2024

Hello again,

We haven't heard back from you in a while regarding this issue. I will go ahead and close this out for the time being. If you're still running into any problems, please feel free to reopen and add any additional details!

from rest-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.