|
1 | | -<html> |
2 | | -<title>prediction-cmdline-sample</title> |
3 | | -<body> |
4 | | - <h2>Instructions for the Prediction V1.5 Command-Line Sample</h2> |
5 | | - |
6 | | - <h3>Browse Online</h3> |
7 | | - |
8 | | - <ul> |
9 | | - <li><a |
10 | | - href="http://code.google.com/p/google-api-java-client/source/browse?repo=samples#hg/prediction-cmdline-sample">Browse |
11 | | - Source</a>, or main file <a |
12 | | - href="http://code.google.com/p/google-api-java-client/source/browse/prediction-cmdline-sample/src/main/java/com/google/api/services/samples/prediction/cmdline/PredictionSample.java?repo=samples">PredictionSample.java</a></li> |
13 | | - </ul> |
14 | | - |
15 | | - <h3>Register Your Application</h3> |
16 | | - |
17 | | - <ul> |
18 | | - <li>Visit the <a href="https://cloud.google.com/console/start/api?id=prediction">Google Cloud |
19 | | - console</a>. |
20 | | - </li> |
21 | | - <li>If necessary, sign in to your Google Account, select or create a project, |
22 | | - and agree to the terms of service. Click Continue.</li> |
23 | | - <li>Select "Installed application" and choose type "Other" under the Installed Application type.</li> |
24 | | - <li>Within "OAuth 2.0 Client ID", click on "Download JSON". Later on, after you check |
25 | | - out the sample project, you will copy this downloaded file (e.g. |
26 | | - <code>~/Downloads/client_secrets.json</code>) to |
27 | | - <a href="src/main/resources/client_secrets.json">src/main/resources/client_secrets.json</a>. |
28 | | - If you skip this step, when trying to run the sample you will get a <code>400 |
29 | | - INVALID_CLIENT</code> error in the browser. |
30 | | - </li> |
31 | | - </ul> |
32 | | - |
33 | | - <p> |
34 | | - You will also need to <a |
35 | | - href='http://code.google.com/apis/storage/docs/signup.html#'>Activate |
36 | | - Google Storage</a>, upload the <a |
37 | | - href="http://code.google.com/apis/predict/docs/language_id.txt">training |
38 | | - data</a> required by the sample to Google Storage. And then edit |
39 | | - <code>OBJECT_PATH</code> |
40 | | - in |
41 | | - <code>PredictionSample.java</code> |
42 | | - to point to the training data. Otherwise, you will get a 400 error "Training |
43 | | - data file not found". |
44 | | - </p> |
45 | | - |
46 | | - <h3>Checkout Instructions</h3> |
47 | | - |
48 | | - <p> |
49 | | - <b>Prerequisites:</b> install <a href="http://java.com">Java 6</a>, <a |
50 | | - href="http://mercurial.selenic.com/">Mercurial</a>, and <a |
51 | | - href="http://maven.apache.org/download.html">Maven</a>. You may need to |
52 | | - set your |
53 | | - <code>JAVA_HOME</code> |
54 | | - . |
55 | | - </p> |
56 | | - |
57 | | - <pre> |
58 | | -cd <i>[someDirectory]</i> |
59 | | -hg clone https://code.google.com/p/google-api-java-client.samples/ google-api-java-client-samples |
60 | | -cd google-api-java-client-samples/prediction-cmdline-sample |
61 | | -cp ~/Downloads/client_secrets.json src/main/resources/client_secrets.json |
62 | | -<i>[editor]</i> src/main/java/com/google/api/services/samples/prediction/cmdline/PredictionSample.java |
63 | | -mvn compile |
64 | | -mvn -q exec:java |
65 | | - </pre> |
66 | | - |
67 | | - <p>To enable logging of HTTP requests and responses (highly recommended |
68 | | - when developing), please take a look at <a href="logging.properties">logging.properties</a>.</p> |
69 | | - |
70 | | - <h3>Setup Project in Eclipse</h3> |
71 | | - |
72 | | - <p> |
73 | | - <b>Prerequisites:</b> install <a href="http://www.eclipse.org/downloads/">Eclipse</a>, |
74 | | - the <a href="http://javaforge.com/project/HGE">Mercurial plugin</a>, and the |
75 | | - <a href="http://m2eclipse.sonatype.org/installing-m2eclipse.html">Maven |
76 | | - plugin</a>. |
77 | | - </p> |
78 | | - |
79 | | - <ul> |
80 | | - <li>Setup Eclipse Preferences |
81 | | - <ul> |
82 | | - <li>Window > Preferences... (or on Mac, Eclipse > |
83 | | - Preferences...)</li> |
84 | | - <li>Select Maven |
85 | | - <ul> |
86 | | - <li>check on "Download Artifact Sources"</li> |
87 | | - <li>check on "Download Artifact JavaDoc"</li> |
88 | | - </ul> |
89 | | - </li> |
90 | | - </ul> |
91 | | - </li> |
92 | | - <li>Import <code>prediction-cmdline-sample</code> project |
93 | | - <ul> |
94 | | - <li>File > Import...</li> |
95 | | - <li>Select "General > Existing Project into Workspace" and click |
96 | | - "Next"</li> |
97 | | - <li>Click "Browse" next to "Select root directory", find <code> |
98 | | - <i>[someDirectory]</i>/google-api-java-client-samples/prediction-cmdline-sample |
99 | | - </code> and click "Next" |
100 | | - </li> |
101 | | - <li>Click "Finish"</li> |
102 | | - </ul> |
103 | | - </li> |
104 | | - <li>Run |
105 | | - <ul> |
106 | | - <li>Right-click on project prediction-cmdline-sample</li> |
107 | | - <li>Run As > Java Application</li> |
108 | | - <li>If asked, type "PredictionSample" and click OK</li> |
109 | | - </ul> |
110 | | - </li> |
111 | | - </ul> |
112 | | - |
113 | | -</body> |
114 | | -</html> |
| 1 | +# prediction-cmdline-sample |
| 2 | + |
| 3 | +## Instructions for the Prediction V1.5 Command-Line Sample |
| 4 | + |
| 5 | +### Browse online |
| 6 | + |
| 7 | +- [Browse Source](https://github.com/google/google-api-java-client-samples/tree/master/prediction-cmdline-sample), |
| 8 | + or [main file](https://github.com/google/google-api-java-client-samples/blob/master/prediction-cmdline-sample/src/main/java/com/google/api/services/samples/prediction/cmdline/PredictionSample.java). |
| 9 | + |
| 10 | +### Register your application |
| 11 | + |
| 12 | +- Enable the Prediction API in the [Google Developers Console](https://console.developers.google.com/projectselector/apis/api/prediction/overview). |
| 13 | +- Create a service account from the [Permissions](https://console.developers.google.com/permissions/serviceaccounts) |
| 14 | + page. Download the service account's private key in P12 format. Later on, |
| 15 | + after you check out the sample project, you will copy this downloaded file |
| 16 | + (e.g. `MyProject-123456.p12`) to the `src/main/resources/` directory, and then |
| 17 | + edit `PROJECT_ID`, `SERVICE_ACCT_EMAIL`, and `SERVICE_ACCT_KEYFILE` in |
| 18 | + `PredictionSample.java`. |
| 19 | +- [Activate Google Storage](http://code.google.com/apis/storage/docs/signup.html), |
| 20 | + upload the [training data](http://code.google.com/apis/predict/docs/language_id.txt) |
| 21 | + required by the sample to Google Storage, and then edit `OBJECT_PATH` in |
| 22 | + `PredictionSample.java` to point to the training data. Otherwise, you will get |
| 23 | + a 400 error "Training data file not found". |
| 24 | + |
| 25 | +### Check out and run the sample |
| 26 | + |
| 27 | +**Prerequisites:** install [Java](http://java.com), [Git](https://git-scm.com/), |
| 28 | +and [Maven](http://maven.apache.org/download.html). You might need to set your |
| 29 | +`JAVA_HOME`. |
| 30 | + |
| 31 | + cd [someDirectory] |
| 32 | + git clone https://github.com/google/google-api-java-client-samples.git |
| 33 | + cd google-api-java-client-samples/prediction-cmdline-sample |
| 34 | + cp ~/Downloads/MyProject-12345abcd.p12 src/main/resources/ |
| 35 | + [editor] src/main/java/com/google/api/services/samples/prediction/cmdline/PredictionSample.java |
| 36 | + mvn compile |
| 37 | + mvn -q exec:java |
| 38 | + |
| 39 | +To enable logging of HTTP requests and responses (highly recommended when |
| 40 | +developing), take a look at [`logging.properties`](logging.properties). |
0 commit comments