MyJohnDeereAPI-OAuth-Java-Client

System Requirments

Download Java JDK 1.7 or higher, set the JAVA_HOME variable, adjust memory settings, and download and install Apache Maven.

Set the JAVA_HOME Variable:

  1. Right-click the My Computer icon on your desktop and select Properties.
  2. Click the Advanced tab.
  3. Click the Environment Variables button.
  4. Under System Variables, click New.
  5. Enter the variable name as JAVA_HOME.
  6. Enter the variable value as the installation path for the Java Development Kit.
    • If your Java installation directory has a space in its path name, you should use the shortened path name (e.g. C:\Progra~1\Java\jdk1.7.0_25\jre) in the environment variable instead.
    • Note for Windows users on 64-bit systems:
      • Progra~1 = 'Program Files'
      • Progra~2 = 'Program Files(x86)'
  7. Click OK and then click Apply Changes.
  8. Close any command windows that were open before you made these changes and open a new command window. There is no way to reload environment variables from an active command prompt. If the changes do not take effect after reopening the command window, restart Windows.
  9. Run the command. You will see the following on the screen:

java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

Adjust memory settings to increase available Java memory or a fix a "Perm Gen Out of Memory" issue:

  1. Right-click the My Computer icon on your desktop and select Properties.
  2. Click the Advanced tab.
  3. Click the Environment Variables button.
  4. Under System Variables, click New.
  5. Enter the variable name JAVA_OPTS
  6. Enter the variable value as -Xmx1024m -XX:MaxPermSize=512m
  7. Click OK and then click Apply Changes.

Download & Install Apache Maven

  1. Download and Install at least version 3.2 of Maven.
  2. Unzip the distribution archive (i.e. apache-maven-3.0.5-bin.zip) to the directory you wish to install Maven 3.0.5. These instructions assume you chose C:\maven\.
  3. Right-click the My Computer icon on your desktop and select Properties.
  4. Click Advanced System Settings, and then click on Environment Variables.
  5. Add the following new system variables:
Name Value
M2_HOME <path to maven root dir; eg c:\maven\>
M2 %M2_HOME%\bin
MAVEN_OPTS -Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m -Xss10m

Edit the path environmental variable and add the M2 var to it: ...;%M2%;. Then open a terminal and run mvn --version to verify the installation.

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da;
Maven home: C:\maven\apache-maven-3.0.5
Java version: 1.7.0_67, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_67\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

Set up and run the sample app:

  1. Copy the App ID and Shared secret of your App from developer.deere.com to CLIENT variable in ApiCredentials.java.
  2. Run the command mvn clean compile test install package to clean, compile, test, install and package the code.
  3. Run the command mvn exec:java -Dexec.mainClass="com.deere.democlient.GetOAuthToken"
  4. The system will then show this message:

Please provide the verifier from https://my.deere.com/consentToUseOfData?oauth_token={the request token generated by the given App Id and Secret in the Get Oauth Token code}

Copy the URL to a browser and login to MyJohnDeere using your MyJohnDeere username and password. The browser will then display the Verifier Code

Copy the verifier code just below the system message in the command prompt and hit "Enter". This will generate the oAuth token and secret, as shown below:

Token: {a token}
Token Secret: {a token secret}

Copy this token and secret and pass it as a constructor argument to OAuthToken TOKEN = new OAuthToken("a token ", " a token secret "); in the ApiCredentials class. Then run the command to build Maven again:

mvn package

You can run the partnerships class using the below command:

mvn exec:java -Dexec.mainClass="com.deere.democlient.apis.Partnerships"