Skip to content

Commit e11b33d

Browse files
authored
Merge branch 'develop' into 4829-ltv2-deprecation
2 parents 0980594 + c68b3ad commit e11b33d

File tree

13 files changed

+81
-340
lines changed

13 files changed

+81
-340
lines changed

README.md

Lines changed: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ Use this SDK to build Watson-powered applications in Unity.
2525
## Before you begin
2626
Ensure that you have the following prerequisites:
2727

28-
* An IBM Cloud account. If you don't have one, [sign up][ibm_cloud_registration].
28+
* You need an [IBM Cloud][ibm-cloud-onboarding] account.
2929
* [Unity][get_unity]. You can use the **free** Personal edition.
30+
31+
## Configuring Unity
3032
* Change the build settings in Unity (**File > Build Settings**) to any platform except for web player/Web GL. The Watson Developer Cloud Unity SDK does not support Unity Web Player.
33+
* If using Unity 2018.2 or later you'll need to set Scripting Runtime Version in Build Settings to .NET 4.x equivalent. We need to access security options to enable TLS 1.2.
3134

3235
## Getting the Watson SDK and adding it to Unity
3336
You can get the latest SDK release by clicking [here][latest_release].
@@ -75,50 +78,44 @@ To get started with the Watson Services in Unity, click on each service below to
7578
* [Visual Recognition](/Scripts/Services/VisualRecognition/v3)
7679

7780
## Authentication
78-
Before you can use a service, it must be authenticated with the service instance's `username`, `password` and `url`.
81+
Watson services are migrating to token-based Identity and Access Management (IAM) authentication.
7982

80-
```cs
81-
using IBM.Watson.DeveloperCloud.Services.Assistant.v1;
82-
using IBM.Watson.DeveloperCloud.Utilities;
83+
- With some service instances, you authenticate to the API by using **[IAM](#iam)**.
84+
- In other instances, you authenticate by providing the **[username and password](#username-and-password)** for the service instance.
85+
- Visual Recognition uses a form of [API key](#api-key) only with instances created before May 23, 2018. Newer instances of Visual Recognition use [IAM](#iam).
8386

84-
void Start()
85-
{
86-
Credentials credentials = new Credentials(<username>, <password>, <url>);
87-
Assistant _assistant = new Assistant(credentials);
88-
}
89-
```
87+
### Getting credentials
88+
To find out which authentication to use, view the service credentials. You find the service credentials for authentication the same way for all Watson services:
9089

91-
For services that authenticate using an apikey, you can instantiate the service instance using a `Credential` object with an `apikey` and `url`.
90+
1. Go to the IBM Cloud **[Dashboard][watson-dashboard]** page.
91+
1. Either click an existing Watson service instance or click **Create**.
92+
1. Click **Show** to view your service credentials.
93+
1. Copy the `url` and either `apikey` or `username` and `password`.
9294

93-
**Important**: Instantiation with `apikey` works only with Visual Recognition service instances created before May 23, 2018. Visual Recognition instances created after May 22 use IAM.
95+
In your code, you can use these values in the service constructor or with a method call after instantiating your service.
9496

95-
```cs
96-
using IBM.Watson.DeveloperCloud.Services.VisualRecognition.v3;
97-
using IBM.Watson.DeveloperCloud.Utilities;
97+
### IAM
9898

99-
void Start()
100-
{
101-
Credentials credentials = new Credentials(<apikey>, <url>);
102-
VisualRecognition _visualRecognition = new VisualRecognition(credentials);
103-
}
104-
```
99+
Some services use token-based Identity and Access Management (IAM) authentication. IAM authentication uses a service API key to get an access token that is passed with the call. Access tokens are valid for approximately one hour and must be regenerated.
100+
101+
You supply either an IAM service **API key** or an **access token**:
105102

106-
You can also authenticate a service using IAM authentication. You can either supply a valid access token in the `iamTokenOptions` or get an access token using an `apikey`.
103+
- Use the API key to have the SDK manage the lifecycle of the access token. The SDK requests an access token, ensures that the access token is valid, and refreshes it if necessary.
104+
- Use the access token if you want to manage the lifecycle yourself. For details, see [Authenticating with IAM tokens](https://console.bluemix.net/docs/services/watson/getting-started-iam.html). If you want to switch to API key, in a coroutine, override your stored IAM credentials with an IAM API key and yield until the credentials object `HasIamTokenData()` returns `true`.
107105

106+
#### Supplying the IAM API key
108107
```cs
109-
void IEnumerator TokenExample()
108+
IEnumerator TokenExample()
110109
{
111110
// Create IAM token options and supply the apikey.
112-
// Alternatively you can supply an access token.
113111
TokenOptions iamTokenOptions = new TokenOptions()
114112
{
115113
IamApiKey = "<iam-api-key>",
116-
IamAccessToken = "<iam-access-token>",
117114
IamUrl = "<service-url>"
118115
};
119116

120117
// Create credentials using the IAM token options
121-
_credentials = new Credentials(iamTokenOptions, "<service-url");
118+
_credentials = new Credentials(iamTokenOptions, "<service-url");
122119
while (!_credentials.HasIamTokenData())
123120
yield return null;
124121

@@ -138,6 +135,61 @@ private void OnFail(RESTConnector.Error error, Dictionary<string, object> custom
138135
}
139136
```
140137

138+
#### Supplying the access token
139+
```cs
140+
void TokenExample()
141+
{
142+
// Create IAM token options and supply the access token.
143+
TokenOptions iamTokenOptions = new TokenOptions()
144+
{
145+
IamAccessToken = "<iam-access-token>"
146+
};
147+
148+
// Create credentials using the IAM token options
149+
_credentials = new Credentials(iamTokenOptions, "<service-url");
150+
151+
_assistant = new Assistant(_credentials);
152+
_assistant.VersionDate = "2018-02-16";
153+
_assistant.ListWorkspaces(OnListWorkspaces, OnFail);
154+
}
155+
156+
private void OnListWorkspaces(WorkspaceCollection response, Dictionary<string, object> customData)
157+
{
158+
Log.Debug("OnListWorkspaces()", "Response: {0}", customData["json"].ToString());
159+
}
160+
161+
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
162+
{
163+
Log.Debug("OnFail()", "Failed: {0}", error.ToString());
164+
}
165+
```
166+
167+
### Username and password
168+
```cs
169+
using IBM.Watson.DeveloperCloud.Services.Assistant.v1;
170+
using IBM.Watson.DeveloperCloud.Utilities;
171+
172+
void Start()
173+
{
174+
Credentials credentials = new Credentials(<username>, <password>, <url>);
175+
Assistant _assistant = new Assistant(credentials);
176+
}
177+
```
178+
179+
### API key
180+
**Important**: This type of authentication works only with Visual Recognition instances created before May 23, 2018. Newer instances of Visual Recognition use [IAM](#iam).
181+
```cs
182+
using IBM.Watson.DeveloperCloud.Services.VisualRecognition.v3;
183+
using IBM.Watson.DeveloperCloud.Utilities;
184+
185+
void Start()
186+
{
187+
Credentials credentials = new Credentials(<apikey>, <url>);
188+
VisualRecognition _visualRecognition = new VisualRecognition(credentials);
189+
}
190+
```
191+
192+
141193
## Callbacks
142194
Success and failure callbacks are required. You can specify the return type in the callback.
143195
```cs
@@ -321,6 +373,7 @@ See [CONTRIBUTING.md](.github/CONTRIBUTING.md).
321373
[wdc]: https://www.ibm.com/watson/developer/
322374
[wdc_unity_sdk]: https://github.com/watson-developer-cloud/unity-sdk
323375
[latest_release]: https://github.com/watson-developer-cloud/unity-sdk/releases/latest
324-
[ibm_cloud_registration]: http://console.bluemix.net/registration?cm_sp=WatsonPlatform-WatsonServices-_-OnPageNavLink-IBMWatson_SDKs-_-Unity
325376
[get_unity]: https://unity3d.com/get-unity
326377
[documentation]: https://watson-developer-cloud.github.io/unity-sdk/
378+
[ibm-cloud-onboarding]: http://console.bluemix.net/registration?target=/developer/watson&cm_sp=WatsonPlatform-WatsonServices-_-OnPageNavLink-IBMWatson_SDKs-_-Unity
379+
[watson-dashboard]: https://console.bluemix.net/dashboard/apps?category=watson

Scripts/Services/Assistant/v1/README.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,6 @@ You complete these steps to implement your application:
99

1010
* Develop your application. You code your application to connect to the Assistant workspace through API calls. You then integrate your app with other systems that you need, including back-end systems and third-party services such as chat services or social media.
1111

12-
### Instantiating and authenticating the service
13-
Before you can send requests to the service it must be instantiated and credentials must be set.
14-
```cs
15-
using IBM.Watson.DeveloperCloud.Services.Assistant.v1;
16-
using IBM.Watson.DeveloperCloud.Utilities;
17-
18-
void Start()
19-
{
20-
Credentials credentials = new Credentials(<username>, <password>, <url>);
21-
Assistant _assistant = new Assistant(credentials);
22-
}
23-
```
24-
25-
### Fail handler
26-
These examples use a common fail handler.
27-
```cs
28-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
29-
{
30-
Log.Error("ExampleAssistant.OnFail()", "Error received: {0}", error.ToString());
31-
}
32-
```
33-
3412
### Message
3513
Send a message to the Assistant instance
3614
```cs

Scripts/Services/Conversation/v1/README.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,6 @@ You complete these steps to implement your application:
99

1010
* Develop your application. You code your application to connect to the Conversation workspace through API calls. You then integrate your app with other systems that you need, including back-end systems and third-party services such as chat services or social media.
1111

12-
### Instantiating and authenticating the service
13-
Before you can send requests to the service it must be instantiated and credentials must be set.
14-
```cs
15-
using IBM.Watson.DeveloperCloud.Services.Conversation.v1;
16-
using IBM.Watson.DeveloperCloud.Utilities;
17-
18-
void Start()
19-
{
20-
Credentials credentials = new Credentials(<username>, <password>, <url>);
21-
Conversation _conversation = new Conversation(credentials);
22-
}
23-
```
24-
25-
### Fail handler
26-
These examples use a common fail handler.
27-
```cs
28-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
29-
{
30-
Log.Error("ExampleConversation.OnFail()", "Error received: {0}", error.ToString());
31-
}
32-
```
33-
3412
### Message
3513
Send a message to the Conversation instance
3614
```cs

Scripts/Services/Discovery/v1/README.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,6 @@ The IBM Watson™ [Discovery][discovery] service makes it possible to rapidly bu
44
## Usage
55
The IBM Watson™ [Discovery][discovery] Service uses data analysis combined with cognitive intuition in order to take your unstructured data and enrich it so that you can query it to return the information that you need from it.
66

7-
### Instantiating and authenticating the service
8-
Before you can send requests to the service it must be instantiated and credentials must be set.
9-
```cs
10-
using IBM.Watson.DeveloperCloud.Services.Discovery.v1;
11-
using IBM.Watson.DeveloperCloud.Utilities;
12-
13-
void Start()
14-
{
15-
Credentials credentials = new Credentials(<username>, <password>, <url>);
16-
Discovery _discovery = new Discovery(credentials);
17-
}
18-
```
19-
20-
### Fail handler
21-
These examples use a common fail handler.
22-
```cs
23-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
24-
{
25-
Log.Error("ExampleDiscovery.OnFail()", "Error received: {0}", error.ToString());
26-
}
27-
```
28-
29-
30-
317
### Create an environment
328
Creates an environment for the service instance. Note: You can create only one environment per service instance. Attempting to create another environment for the same service instance results in an error. See the [Discovery service home page][discovery-sizing] for additional information about sizing and pricing. To create a free trial environment, specify the value of size as 0 (zero).
339
```cs

Scripts/Services/LanguageTranslator/v2/README.md

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,6 @@
77
## Usage
88
Select a domain, then identify or select the language of text, and then translate the text from one supported language to another.
99

10-
### Instantiating and authenticating the service
11-
Before you can send requests to the service it must be instantiated and credentials must be set.
12-
```cs
13-
using IBM.Watson.DeveloperCloud.Services.LanguageTranslator.v2;
14-
using IBM.Watson.DeveloperCloud.Utilities;
15-
16-
void Start()
17-
{
18-
Credentials credentials = new Credentials(<username>, <password>, <url>);
19-
LanguageTranslator _languageTranslator = new LanguageTranslator(credentials);
20-
}
21-
```
22-
23-
24-
You can also authenticate the service with an IAM apikey
25-
```cs
26-
using IBM.Watson.DeveloperCloud.Services.LanguageTranslator.v2;
27-
using IBM.Watson.DeveloperCloud.Utilities;
28-
29-
void Start()
30-
{
31-
Runnable.Run(CreateService());
32-
}
33-
34-
IEnumerator CreateService()
35-
{
36-
TokenOptions tokenOptions = new TokenOptions()
37-
{
38-
IamApiKey = _iamApikey
39-
};
40-
41-
Credentials credentials = new Credentials(tokenOptions);
42-
43-
// Wait for tokendata
44-
while (!credentials.HasIamTokenData())
45-
yield return null;
46-
47-
LanguageTranslator _languageTranslator = new LanguageTranslator(credentials);
48-
}
49-
```
50-
51-
52-
### Fail handler
53-
These examples use a common fail handler.
54-
```cs
55-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
56-
{
57-
Log.Error("ExampleLanguageTranslatorV2.OnFail()", "Error received: {0}", error.ToString());
58-
}
59-
```
60-
61-
62-
6310
### List models
6411
Lists available models for language translation with option to filter by source or by target language.
6512
```cs

Scripts/Services/LanguageTranslator/v3/README.md

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,6 @@
55
## Usage
66
Select a domain, then identify or select the language of text, and then translate the text from one supported language to another.
77

8-
### Instantiating and authenticating the service
9-
Before you can send requests to the service it must be instantiated and credentials must be set.
10-
```cs
11-
using IBM.Watson.DeveloperCloud.Services.LanguageTranslator.v3;
12-
using IBM.Watson.DeveloperCloud.Utilities;
13-
14-
void Start()
15-
{
16-
Credentials credentials = new Credentials(<username>, <password>, <url>);
17-
LanguageTranslator _languageTranslator = new LanguageTranslator(credentials);
18-
}
19-
```
20-
21-
22-
You can also authenticate the service with an IAM apikey
23-
```cs
24-
using IBM.Watson.DeveloperCloud.Services.LanguageTranslator.v3;
25-
using IBM.Watson.DeveloperCloud.Utilities;
26-
27-
IEnumerator CreateService()
28-
{
29-
TokenOptions tokenOptions = new TokenOptions()
30-
{
31-
IamApiKey = _iamApikey
32-
};
33-
34-
Credentials credentials = new Credentials(tokenOptions);
35-
36-
// Wait for tokendata
37-
while (!credentials.HasIamTokenData())
38-
yield return null;
39-
40-
LanguageTranslator _languageTranslator = new LanguageTranslator("<versionDate>", credentials);
41-
}
42-
```
43-
44-
45-
### Fail handler
46-
These examples use a common fail handler.
47-
```cs
48-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
49-
{
50-
Log.Error("ExampleLanguageTranslatorV3V3.OnFail()", "Error received: {0}", error.ToString());
51-
}
52-
```
53-
54-
55-
568
### List models
579
Lists available models for language translation with option to filter by source or by target language.
5810
```cs

Scripts/Services/NaturalLanguageClassifier/v2/README.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,6 @@ Use [Natural Language Classifier][natural_language_classifier] service to create
55
## Usage
66
Classify intents in natural language.
77

8-
### Instantiating and authenticating the service
9-
Before you can send requests to the service it must be instantiated and credentials must be set.
10-
```cs
11-
using IBM.Watson.DeveloperCloud.Services.NaturalLanguageClassifier.v2;
12-
using IBM.Watson.DeveloperCloud.Utilities;
13-
14-
void Start()
15-
{
16-
Credentials credentials = new Credentials(<username>, <password>, <url>);
17-
NaturalLanguageClassifier _naturalLanguageClassifier = new NaturalLanguageClassifier(credentials);
18-
}
19-
```
20-
21-
22-
### Fail handler
23-
These examples use a common fail handler.
24-
```cs
25-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
26-
{
27-
Log.Error("ExampleNaturalLanguageClassifier.OnFail()", "Error received: {0}", error.ToString());
28-
}
29-
```
30-
31-
328
### Listing Classifiers
339
Returns an empty array if no classifiers are available.
3410
```cs

0 commit comments

Comments
 (0)