Tutorial: Using the MTurk API with the AWS SDK for Java
In today's tutorial,we will step through how to setup and make your first API calls again the MTurk API for Java.We will be using the popularEclipse Integrated Development Environment (IDE)and theAWS Toolkit for Eclipse.Let's get started.
To begin,we'll first download and install Eclipse here:
For this tutorial,we'll be using Eclipse Oxygen 3.A (April 2018).Once installed,we'll then install the AWS Toolkit for Eclipse by following these steps:
Now,let's go to theMenubar and selectNewthenProject.A dialog box should appear that will look similar to this:
SelectAWS Java Project,and clickNext >.Now we will be asked to provide a name for our new project (we'll name oursmturk-appfor this tutorial).It should look like this:
If you want to use different credentials than those found in your ~/.aws/credentials file,select them under theAWS Credentialsheader,在Select profile:dropdown.For this tutorial,we will use thedefaultcredentials as shown above.
Next clickFinishto proceed.Once complete,your screen should look similar to this:
Creating our first program
Often,the best place to start when configuring a new language and a new API is to write a simple program to ensure that we're correctly compiling,calling the API,and receiving the expected result.MTurk offers a simple,read-only API calledGetAccountBalancethat is useful to verify that our application is correctly calling the MTurk API.Our first program will be to call that API.
Let's use sample code that's already available in the MTurk Code Samples repository on GitHub here:
mturk-code-samples - Code samples to help you get started with the 万博体育网址Amazon Mechanical Turk Requester APIgithub.com
We'll be working with the sample app calledGetAccountBalanceSamplethat can be foundhere.First,let's create our GetAccountBalanceSample class by clicking the right mouse button on the
src/main/javaand selectingNew > Class.It should look like this:
From there,we will delete all characters in thePackage:field,enter the class nameGetAccountBalanceSampleand clickFinishto proceed.It should look like this:
Next,we will open the sample code from GitHub for GetAccountBalanceSample found here:
and paste it into our editor,completely replacing any existing code in the GetAccountBalanceSample.java file.Once you've pasted it in,your Eclipse IDE screen should look like this:
Now we'll actually run our first program.To do this,click the right mouse button anywhere in the GetAccountBalanceSample.java code editor window.A menu will appear and you'll selectRun AsthenJava Application.It should look like this:
You should see output that looks similar to the following:
SANDBOX - Your account balance is 10000.00
PRODUCTION - Your account balance is 384.72
And your screen should look similar to this:
Congratulations!You've just executed your first Java program calling the MTurk API with the AWS SDK.Nice work.
Today,we've just scratched the surface of what's possible with the AWS SDK for Java and the MTurk Requester API.In future tutorials,we'll build on this to show readers how to do even more.In the meantime,you can learn more about the MTurk API by accessing the MTurk API documentationhere.You can also check out more Java sample code for the AWS SDK and MTurk APIhere.