Last active
December 1, 2017 23:07
-
-
Save akeller/6c05bd79f510bac376ce4c449de55be0 to your computer and use it in GitHub Desktop.
Watson Unity SDK Getting Started - Tone Analyzer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using IBM.Watson.DeveloperCloud.Services.ToneAnalyzer.v3; | |
using IBM.Watson.DeveloperCloud.Utilities; | |
using IBM.Watson.DeveloperCloud.DataTypes; | |
using IBM.Watson.DeveloperCloud.Logging; | |
using IBM.Watson.DeveloperCloud.Connection; | |
using FullSerializer; | |
public class PlayerController : MonoBehaviour | |
{ | |
void Start() | |
{ | |
Credentials credentials = new Credentials(<username>, <password>, "https://gateway.watsonplatform.net/tone-analyzer/api"); | |
ToneAnalyzer _toneAnalyzer = new ToneAnalyzer(credentials); | |
//be sure to give it a Version Date | |
_toneAnalyzer.VersionDate = "2017-09-21"; | |
if (!_toneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, OnFail, "I am really so angry we lost the game!")) | |
Log.Debug("ExampleToneAnalyzer.GetToneAnalyze()", "Failed to analyze!"); | |
} | |
private void OnGetToneAnalyze(ToneAnalyzerResponse resp, Dictionary<string, object> customData) | |
{ | |
Debug.Log(customData["json"].ToString()); | |
} | |
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData) | |
{ | |
Log.Error("ExampleToneAnalyzer.OnFail()", "Error received: {0}", error.ToString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment