cd [someDirectory]
-hg clone https://code.google.com/p/google-api-java-client.samples/ google-api-java-client-samples
+git clone https://github.com/google/google-api-java-client-samples.git
cd google-api-java-client-samples/calendar-android-sample
@@ -101,8 +103,8 @@
Set Up Project in Android Studio
Run this command in a terminal:
$ANDROID_HOME/tools/android sdk
-
Under "Tools", check on "Android SDK Build-tools" revision 18.0.1.
-
Under "Android 2.2 (API 8)", check on "SDK Platform" and "Google APIs".
+
Under "Tools", check on "Android SDK Build-tools" revision 22.0.1.
+
Under "Android 5.1.1 (API 22)", check on "SDK Platform" and "Google APIs".
Under "Extras", check on "Android Support Repository", "Android Support Library",
and "Google Repository".
@@ -126,11 +128,12 @@
Set Up Project in Android Studio
Select "Use local gradle distribution" with "Gradle home" of
- [someDirectory]/gradle-1.6 and click OK.
+ [someDirectory]/gradle-2.2.1 and click OK.
-
Open AndroidManifest.xml and change the package to match the name you registered in the
+
Open AndroidManifest.xml and change the package attribute of the manifest, initially
+ "com.google.api.services.samples.calendar.android", to match the name you registered in the
Google Cloud Console, e.g. "org.example.calendar.janedoe20130911".
Rename the Java package: right-click on src/main/java, click New, click Package, and then
diff --git a/calendar-appengine-sample/pom.xml b/calendar-appengine-sample/pom.xml
index 5e96ed0b..c3943ef2 100644
--- a/calendar-appengine-sample/pom.xml
+++ b/calendar-appengine-sample/pom.xml
@@ -267,7 +267,7 @@
com.google.apisgoogle-api-services-calendar
- v3-rev87-1.19.0
+ v3-rev260-1.23.0com.google.api-client
diff --git a/calendar-cmdline-sample/pom.xml b/calendar-cmdline-sample/pom.xml
index cc201419..cea49bd5 100644
--- a/calendar-cmdline-sample/pom.xml
+++ b/calendar-cmdline-sample/pom.xml
@@ -114,7 +114,7 @@
com.google.apisgoogle-api-services-calendar
- v3-rev87-1.19.0
+ v3-rev260-1.23.0com.google.http-client
@@ -128,8 +128,8 @@
- 1.19.0
- 1.19.0
+ 1.23.0
+ 1.23.0UTF-8
diff --git a/compute-engine-cmdline-sample/pom.xml b/compute-engine-cmdline-sample/pom.xml
index 38aeb1ab..7d56d090 100644
--- a/compute-engine-cmdline-sample/pom.xml
+++ b/compute-engine-cmdline-sample/pom.xml
@@ -124,12 +124,12 @@
com.google.apisgoogle-api-services-compute
- v1-rev27-1.19.0
+ v1-rev158-1.23.0
- 1.19.0
- 1.19.0
+ 1.23.0
+ 1.23.0UTF-8
diff --git a/dfareporting-cmdline-sample/pom.xml b/dfareporting-cmdline-sample/pom.xml
index 7442eb3b..a923851a 100644
--- a/dfareporting-cmdline-sample/pom.xml
+++ b/dfareporting-cmdline-sample/pom.xml
@@ -109,7 +109,7 @@
com.google.apisgoogle-api-services-dfareporting
- v1.3-rev21-1.19.0
+ v2.8-rev2-1.23.0com.google.http-client
@@ -128,8 +128,8 @@
- 1.19.0
- 1.19.0
+ 1.23.0
+ 1.23.0UTF-8
diff --git a/discovery-cmdline-sample/pom.xml b/discovery-cmdline-sample/pom.xml
index 81b1137f..403942d6 100644
--- a/discovery-cmdline-sample/pom.xml
+++ b/discovery-cmdline-sample/pom.xml
@@ -137,7 +137,7 @@
com.google.apisgoogle-api-services-discovery
- v1-rev45-1.19.0
+ v1-rev61-1.23.0com.google.http-client
@@ -156,8 +156,8 @@
- 1.19.0
- 1.19.0
+ 1.23.0
+ 1.23.0UTF-8
diff --git a/drive-cmdline-sample/pom.xml b/drive-cmdline-sample/pom.xml
index 021ea2cc..5e386d33 100644
--- a/drive-cmdline-sample/pom.xml
+++ b/drive-cmdline-sample/pom.xml
@@ -114,7 +114,7 @@
com.google.apisgoogle-api-services-drive
- v2-rev135-1.19.0
+ v3-rev86-1.23.0com.google.http-client
@@ -133,8 +133,8 @@
- 1.19.0
- 1.19.0
+ 1.23.0
+ 1.23.0UTF-8
diff --git a/fusiontables-cmdline-sample/pom.xml b/fusiontables-cmdline-sample/pom.xml
index 2764723f..90e3aa50 100644
--- a/fusiontables-cmdline-sample/pom.xml
+++ b/fusiontables-cmdline-sample/pom.xml
@@ -112,7 +112,7 @@
com.google.apisgoogle-api-services-fusiontables
- v1-rev52-1.19.0
+ v2-rev19-1.23.0com.google.http-client
@@ -126,8 +126,8 @@
- 1.19.0
- 1.19.0
+ 1.23.0
+ 1.23.0UTF-8
diff --git a/oauth2-cmdline-sample/pom.xml b/oauth2-cmdline-sample/pom.xml
index 8a8bf7e1..f09b2f5e 100644
--- a/oauth2-cmdline-sample/pom.xml
+++ b/oauth2-cmdline-sample/pom.xml
@@ -114,7 +114,7 @@
com.google.apisgoogle-api-services-oauth2
- v2-rev75-1.19.0
+ v2-rev131-1.23.0com.google.http-client
@@ -128,8 +128,8 @@
- 1.19.0
- 1.19.0
+ 1.23.0
+ 1.23.0UTF-8
diff --git a/plus-appengine-sample/pom.xml b/plus-appengine-sample/pom.xml
index ca722623..b239b342 100644
--- a/plus-appengine-sample/pom.xml
+++ b/plus-appengine-sample/pom.xml
@@ -33,7 +33,7 @@
- 1.19.0
+ 1.23.01.8.3${project.build.directory}/${project.build.finalName}
@@ -160,7 +160,7 @@
com.google.apisgoogle-api-services-plus
- v1-rev137-1.19.0
+ v1-rev530-1.23.0com.google.api-client
diff --git a/plus-cmdline-sample/pom.xml b/plus-cmdline-sample/pom.xml
index 611b0f15..04090bec 100644
--- a/plus-cmdline-sample/pom.xml
+++ b/plus-cmdline-sample/pom.xml
@@ -114,7 +114,7 @@
com.google.apisgoogle-api-services-plus
- v1-rev137-1.19.0
+ v1-rev530-1.23.0com.google.http-client
@@ -128,8 +128,8 @@
- 1.19.0
- 1.19.0
+ 1.23.0
+ 1.23.0UTF-8
diff --git a/plus-preview-appengine-sample/pom.xml b/plus-preview-appengine-sample/pom.xml
index 382e5a12..008b6089 100644
--- a/plus-preview-appengine-sample/pom.xml
+++ b/plus-preview-appengine-sample/pom.xml
@@ -34,7 +34,7 @@
- 1.15.0-rc
+ 1.23.0${project.build.directory}/${project.build.finalName}
UTF-8
@@ -163,7 +163,7 @@
com.google.apisgoogle-api-services-plus
- v1-rev137-1.19.0
+ v1-rev530-1.23.0com.google.api-client
diff --git a/plus-preview-appengine-sample/src/main/java/com/google/api/services/samples/plus/Utils.java b/plus-preview-appengine-sample/src/main/java/com/google/api/services/samples/plus/Utils.java
index 6b3d9219..e5f21649 100644
--- a/plus-preview-appengine-sample/src/main/java/com/google/api/services/samples/plus/Utils.java
+++ b/plus-preview-appengine-sample/src/main/java/com/google/api/services/samples/plus/Utils.java
@@ -19,7 +19,7 @@
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.http.GenericUrl;
-import com.google.api.client.json.jackson.JacksonFactory;
+import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.Preconditions;
import com.google.api.services.plus.PlusScopes;
import com.google.appengine.api.users.User;
diff --git a/plus-serviceaccount-cmdline-sample/pom.xml b/plus-serviceaccount-cmdline-sample/pom.xml
index b485af8c..21564ba1 100644
--- a/plus-serviceaccount-cmdline-sample/pom.xml
+++ b/plus-serviceaccount-cmdline-sample/pom.xml
@@ -114,7 +114,7 @@
com.google.apisgoogle-api-services-plus
- v1-rev137-1.19.0
+ v1-rev530-1.23.0com.google.http-client
@@ -128,7 +128,7 @@
- 1.19.0
+ 1.23.0UTF-8
diff --git a/prediction-cmdline-sample/README.md b/prediction-cmdline-sample/README.md
new file mode 100644
index 00000000..0a357858
--- /dev/null
+++ b/prediction-cmdline-sample/README.md
@@ -0,0 +1,46 @@
+# prediction-cmdline-sample
+
+## Instructions for the Prediction V1.6 Command-Line Sample
+
+### Browse online
+
+- [Browse Source]
+ (https://github.com/google/google-api-java-client-samples/tree/master/prediction-cmdline-sample),
+ 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).
+
+### Register your application
+
+- Enable the Prediction API in the [Google Developers Console]
+ (https://console.developers.google.com/projectselector/apis/api/prediction/overview).
+- Create a service account from the [Permissions]
+ (https://console.developers.google.com/permissions/serviceaccounts) page.
+ When you create the service account, select **Furnish a new private key**
+ and download the service account's private key in P12 format. Later on, after
+ you check out the sample project, you will copy this downloaded file (e.g.
+ `MyProject-123456.p12`) to the `src/main/resources/` directory, and then
+ edit `PROJECT_ID`, `SERVICE_ACCT_EMAIL`, and `SERVICE_ACCT_KEYFILE` in
+ `PredictionSample.java`.
+- [Activate Google Storage]
+ (http://code.google.com/apis/storage/docs/signup.html), upload the [training
+ data](http://code.google.com/apis/predict/docs/language_id.txt) required by
+ the sample to Google Storage, and then edit `OBJECT_PATH` in
+ `PredictionSample.java` to point to the training data. Otherwise, you will
+ get a 400 error "Training data file not found".
+
+### Check out and run the sample
+
+**Prerequisites:** install [Java](http://java.com), [Git](https://git-scm.com/),
+and [Maven](http://maven.apache.org/download.html). You might need to set your
+`JAVA_HOME`.
+
+ cd [someDirectory]
+ git clone https://github.com/google/google-api-java-client-samples.git
+ cd google-api-java-client-samples/prediction-cmdline-sample
+ cp ~/Downloads/MyProject-12345abcd.p12 src/main/resources/
+ [editor] src/main/java/com/google/api/services/samples/prediction/cmdline/PredictionSample.java
+ mvn compile
+ mvn -q exec:java
+
+To enable logging of HTTP requests and responses (highly recommended when
+developing), take a look at [`logging.properties`](logging.properties).
diff --git a/prediction-cmdline-sample/instructions.html b/prediction-cmdline-sample/instructions.html
deleted file mode 100644
index 06513358..00000000
--- a/prediction-cmdline-sample/instructions.html
+++ /dev/null
@@ -1,114 +0,0 @@
-
-prediction-cmdline-sample
-
-
Instructions for the Prediction V1.5 Command-Line Sample
If necessary, sign in to your Google Account, select or create a project,
- and agree to the terms of service. Click Continue.
-
Select "Installed application" and choose type "Other" under the Installed Application type.
-
Within "OAuth 2.0 Client ID", click on "Download JSON". Later on, after you check
- out the sample project, you will copy this downloaded file (e.g.
- ~/Downloads/client_secrets.json) to
- src/main/resources/client_secrets.json.
- If you skip this step, when trying to run the sample you will get a 400
- INVALID_CLIENT error in the browser.
-
-
-
-
- You will also need to Activate
- Google Storage, upload the training
- data required by the sample to Google Storage. And then edit
- OBJECT_PATH
- in
- PredictionSample.java
- to point to the training data. Otherwise, you will get a 400 error "Training
- data file not found".
-
-
-
Checkout Instructions
-
-
- Prerequisites: install Java 6, Mercurial, and Maven. You may need to
- set your
- JAVA_HOME
- .
-
Window > Preferences... (or on Mac, Eclipse >
- Preferences...)
-
Select Maven
-
-
check on "Download Artifact Sources"
-
check on "Download Artifact JavaDoc"
-
-
-
-
-
Import prediction-cmdline-sample project
-
-
File > Import...
-
Select "General > Existing Project into Workspace" and click
- "Next"
-
Click "Browse" next to "Select root directory", find
- [someDirectory]/google-api-java-client-samples/prediction-cmdline-sample
- and click "Next"
-
-
Click "Finish"
-
-
-
Run
-
-
Right-click on project prediction-cmdline-sample
-
Run As > Java Application
-
If asked, type "PredictionSample" and click OK
-
-
-
-
-
-
diff --git a/prediction-cmdline-sample/pom.xml b/prediction-cmdline-sample/pom.xml
index 4592b156..66a43be2 100644
--- a/prediction-cmdline-sample/pom.xml
+++ b/prediction-cmdline-sample/pom.xml
@@ -9,13 +9,13 @@
com.google.apis-samplesprediction-cmdline-sample1.0.0
- Example for the Google Prediction API v1.4 using JSON and OAuth 2.
+ Example for the Google Prediction API v1.6
- http://code.google.com/p/google-api-java-client/
+ https://github.com/google/google-api-java-client
- code.google.com
- http://code.google.com/p/google-api-java-client/issues/list
+ GitHub
+ https://github.com/google/google-api-java-client/issues2011
@@ -25,9 +25,9 @@
- scm:hg:https://samples.google-api-java-client.googlecode.com/hg/
- scm:hg:https://samples.google-api-java-client.googlecode.com/hg/
- http://code.google.com/p/google-api-java-client/source/browse/?repo=samples
+ scm:git:https://github.com/google/google-api-java-client-samples.git
+ scm:git:https://github.com/google/google-api-java-client-samples.git
+ https://github.com/google/google-api-java-client-samples/tree/master/prediction-cmdline-sample
@@ -114,7 +114,12 @@
com.google.apisgoogle-api-services-prediction
- v1.5-rev55-1.19.0
+ v1.6-rev66-1.23.0
+
+
+ com.google.apis
+ google-api-services-storage
+ v1-rev112-1.23.0com.google.http-client
@@ -128,8 +133,8 @@
- 1.19.0
- 1.19.0
+ 1.23.0
+ 1.23.0UTF-8
diff --git a/prediction-cmdline-sample/src/main/java/com/google/api/services/samples/prediction/cmdline/PredictionSample.java b/prediction-cmdline-sample/src/main/java/com/google/api/services/samples/prediction/cmdline/PredictionSample.java
index bfc4fa9e..32738334 100644
--- a/prediction-cmdline-sample/src/main/java/com/google/api/services/samples/prediction/cmdline/PredictionSample.java
+++ b/prediction-cmdline-sample/src/main/java/com/google/api/services/samples/prediction/cmdline/PredictionSample.java
@@ -14,28 +14,25 @@
package com.google.api.services.samples.prediction.cmdline;
-import com.google.api.client.auth.oauth2.Credential;
-import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
-import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
-import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
-import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
+import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
-import com.google.api.client.util.store.DataStoreFactory;
-import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.prediction.Prediction;
import com.google.api.services.prediction.PredictionScopes;
import com.google.api.services.prediction.model.Input;
import com.google.api.services.prediction.model.Input.InputInput;
+import com.google.api.services.prediction.model.Insert;
+import com.google.api.services.prediction.model.Insert2;
import com.google.api.services.prediction.model.Output;
-import com.google.api.services.prediction.model.Training;
+import com.google.api.services.storage.StorageScopes;
import java.io.IOException;
-import java.io.InputStreamReader;
+import java.io.File;
+import java.util.Arrays;
import java.util.Collections;
/**
@@ -47,20 +44,19 @@ public class PredictionSample {
* Be sure to specify the name of your application. If the application name is {@code null} or
* blank, the application will log a warning. Suggested format is "MyCompany-ProductName/1.0".
*/
- private static final String APPLICATION_NAME = "";
+ private static final String APPLICATION_NAME = "HelloPrediction";
- static final String MODEL_ID = "mymodel";
- static final String STORAGE_DATA_LOCATION = "enter_bucket/language_id.txt";
-
- /** Directory to store user credentials. */
- private static final java.io.File DATA_STORE_DIR =
- new java.io.File(System.getProperty("user.home"), ".store/prediction_sample");
+ /** Specify the Cloud Storage location of the training data. */
+ static final String STORAGE_DATA_LOCATION = "your_bucket/language_id.txt";
+ static final String MODEL_ID = "languageidentifier";
/**
- * Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
- * globally shared instance across your application.
+ * Specify your Google Developers Console project ID, your service account's email address, and
+ * the name of the P12 file you copied to src/main/resources/.
*/
- private static FileDataStoreFactory dataStoreFactory;
+ static final String PROJECT_ID = "your-project-1234";
+ static final String SERVICE_ACCT_EMAIL = "account123@your-project-1234.iam.gserviceaccount.com";
+ static final String SERVICE_ACCT_KEYFILE = "YourProject-123456789abc.p12";
/** Global instance of the HTTP transport. */
private static HttpTransport httpTransport;
@@ -69,31 +65,22 @@ public class PredictionSample {
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
/** Authorizes the installed application to access user's protected data. */
- private static Credential authorize() throws Exception {
- // load client secrets
- GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
- new InputStreamReader(PredictionSample.class.getResourceAsStream("/client_secrets.json")));
- if (clientSecrets.getDetails().getClientId().startsWith("Enter")
- || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
- System.out.println(
- "Enter Client ID and Secret from https://code.google.com/apis/console/?api=prediction "
- + "into prediction-cmdline-sample/src/main/resources/client_secrets.json");
- System.exit(1);
- }
- // set up authorization code flow
- GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
- httpTransport, JSON_FACTORY, clientSecrets,
- Collections.singleton(PredictionScopes.PREDICTION)).setDataStoreFactory(
- dataStoreFactory).build();
- // authorize
- return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
+ private static GoogleCredential authorize() throws Exception {
+ return new GoogleCredential.Builder()
+ .setTransport(httpTransport)
+ .setJsonFactory(JSON_FACTORY)
+ .setServiceAccountId(SERVICE_ACCT_EMAIL)
+ .setServiceAccountPrivateKeyFromP12File(new File(
+ PredictionSample.class.getResource("/"+SERVICE_ACCT_KEYFILE).getFile()))
+ .setServiceAccountScopes(Arrays.asList(PredictionScopes.PREDICTION,
+ StorageScopes.DEVSTORAGE_READ_ONLY))
+ .build();
}
private static void run() throws Exception {
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
- dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
// authorization
- Credential credential = authorize();
+ GoogleCredential credential = authorize();
Prediction prediction = new Prediction.Builder(
httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
train(prediction);
@@ -103,26 +90,27 @@ private static void run() throws Exception {
}
private static void train(Prediction prediction) throws IOException {
- Training training = new Training();
- training.setId(MODEL_ID);
- training.setStorageDataLocation(STORAGE_DATA_LOCATION);
- prediction.trainedmodels().insert(training).execute();
+ Insert trainingData = new Insert();
+ trainingData.setId(MODEL_ID);
+ trainingData.setStorageDataLocation(STORAGE_DATA_LOCATION);
+ prediction.trainedmodels().insert(PROJECT_ID, trainingData).execute();
System.out.println("Training started.");
System.out.print("Waiting for training to complete");
System.out.flush();
int triesCounter = 0;
+ Insert2 trainingModel;
while (triesCounter < 100) {
// NOTE: if model not found, it will throw an HttpResponseException with a 404 error
try {
- HttpResponse response = prediction.trainedmodels().get(MODEL_ID).executeUnparsed();
+ HttpResponse response = prediction.trainedmodels().get(PROJECT_ID, MODEL_ID).executeUnparsed();
if (response.getStatusCode() == 200) {
- training = response.parseAs(Training.class);
- String trainingStatus = training.getTrainingStatus();
+ trainingModel = response.parseAs(Insert2.class);
+ String trainingStatus = trainingModel.getTrainingStatus();
if (trainingStatus.equals("DONE")) {
System.out.println();
System.out.println("Training completed.");
- System.out.println(training.getModelInfo());
+ System.out.println(trainingModel.getModelInfo());
return;
}
}
@@ -154,7 +142,7 @@ private static void predict(Prediction prediction, String text) throws IOExcepti
InputInput inputInput = new InputInput();
inputInput.setCsvInstance(Collections.
Select "Use local gradle distribution" with "Gradle home" of
- [someDirectory]/gradle-1.6 and click OK.
+ [someDirectory]/gradle-2.2.1 and click OK.
-
Open AndroidManifest.xml and change the package to match the name you registered in the
+
Open AndroidManifest.xml and change the package attribute of the manifest, initially
+ "com.google.api.services.samples.tasks.android", to match the name you registered in the
Google Cloud Console, e.g. "org.example.tasks.janedoe20130911".
Rename the Java package: right-click on src/main/java, click New, click Package, and then
diff --git a/urlshortener-robots-appengine-sample/pom.xml b/urlshortener-robots-appengine-sample/pom.xml
index a3a9c6df..3c7e3623 100644
--- a/urlshortener-robots-appengine-sample/pom.xml
+++ b/urlshortener-robots-appengine-sample/pom.xml
@@ -49,8 +49,8 @@
1.1.5
- 1.8.3
- 1.19.0
+ 1.9.58
+ 1.23.0${project.build.directory}/${project.build.finalName}
UTF-8
@@ -244,7 +244,7 @@
com.google.apisgoogle-api-services-urlshortener
- v1-rev33-1.19.0
+ v1-rev49-1.23.0com.google.appengine