In the previous post we created a simple WAK HTTP operation and retrieved a blob of unusable data from Instagram.

What we need to do with that JSON blob is to generate C# classes from it so that the response can be accessed in Unity.  The simplest way to go about this, even before creating our HTTP operation, is to get a sample of the response from tools such as the APIGEE Console or use Postman for your own private APIs.

 

  • Step 1: Get the JSON Blob

Go to the APIGEE Console for Instagram and select OAuth2 from the Authentication dropdown.  Then follow the prompts to allow APIGEE access to your Instagram account.  At this point the Authentication dropdown should say ‘instagram-AuthenticatedUser’.  From the API Method selection pick the method we have been working with: ‘tags/{tag-name}/media/recent’.  Directly in the Request URL you can replace ‘{tag-name}’ with ‘games’ and press Send.  Once a response arrives, click the Snapshot button.  At the Snapshot screen, click the View Raw link and copy all of the JSON data into the clipboard.

Screen Shot 2015-07-02 at 10.35.08 AM

 

  • Step 2: Generate C# Classes

With the raw JSON text in our clipboard go to JSONUtils.com.  Clear out the ‘JSON Text or URL’ field and paste in your JSON text.  Click Submit.  You just generated a C# representation of the JSON data!

Copy the C# code found in the lower pane and paste it below your HTTP operation.  Notice that the generated class named ‘Example’ is the root class of the response.

NOTE: Replace all instances of IList to either List or an array.

  • Step 3: Update Operation

Let’s modify our operation a little and add the following class field.

[hg.ApiWebKit.mappers.HttpResponseJsonBody]
public Example Response;

The attribute [HttpResponseJsonBody] evaluates the returned JSON text and maps it to an instance of the Example class.

Screen Shot 2015-07-02 at 10.46.18 AM

 

It is time to run our operation again.  Attach the debugger and place a breakpoint within the ‘on_complete’ block.

Below is the response which we can now use within our app.

Screen Shot 2015-07-02 at 10.52.58 AM

 

In the next post we will take a look on how to send and receive data with assets such as BestHTTP, UniWeb, or UnityHTTP.

Next: Switching WAK Provider

Previous: Inside WAK Operations

Related Articles

WAK: MQTT for IoT – Brief Documentation

Read about MQTT here. Setting up your scene: 1. Create a GameObject. 2. Add the following scripts: ConnectionBroker, DesktopClient, and…

WAK FAQ [1]

Here are answers to questions a potential user asked recently. Previous: OAuth2 in Unity

OAuth Overview in Unity

Below is one of the OAuth flows available in the WAK OAuth Token Interceptor asset. Next: WAK FAQ 1 Previous: Switching WAK…