watson-developer-cloud / android-sdk

:high_brightness: Android SDK to use the IBM Watson services.
http://watson-developer-cloud.github.io/android-sdk/
Apache License 2.0
146 stars 94 forks source link

update example to include updated api key login #70

Closed himuragaming closed 5 years ago

himuragaming commented 5 years ago

I first posted this over at stackoverflow but I get no support there as to what the code would be for getting data from ibm watson over an api key. Please update the example to include use of the latest way to login. thanks

lpatino10 commented 5 years ago

Hey @himuragaming. It looks like the repo you linked to in that issue was a deprecated speech library we used to have, but this is the correct one.

This library is built to work with the Java SDK, so that's where you can find information on how to authenticate with your service. Specifically though, you'll want to look in this section.

To put everything here, if you have your API key in your resources, you can do the following:

SpeechToText service = new SpeechToText();
IamOptions options = new IamOptions.Builder()
  .apiKey(R.string.stt_api_key) // this is your API key
  .build();
service.setIamCredentials(options);

Make sure to bring in the Java SDK as a dependency for this. The latest version to add to your Gradle config is:

compile 'com.ibm.watson.developer_cloud:java-sdk:6.14.0'

You should now be able to make authenticated API calls using that service object.