@iwasaki 306views 更新:2014年10月31日


事前に外部からアクセスできるように以下のURLに載っている「Accessing the Datastore API from another platform」の手順を実施しておきます。

  1. Use the Enable Datastore API Wizard to activate the Datastore API. The wizard allows you to activate the API for an existing project, or create a new project and activate it for that.
  2. In the left sidebar, under APIs & auth, select Credentials.
  3. Click on Create new Client ID.
  4. Select Service account and then click Create Client ID. Your browser will download the private key.
  5. Your Service Account is the Email address displayed under the Service Account section.
  6. Your Private Key is the file you just downloaded.
  7. Your Dataset ID is your new or existing Cloud Project ID.


export DATASTORE_SERVICE_ACCOUNT=<service-account>
export DATASTORE_PRIVATE_KEY_FILE=<path-to-private-key-file>



public static final String ACCOUNT = "accountname"; public static final String PROJECT_ID = "projectname"; public static final String PRIVATE_KEY_FILE = "keyfilename"; /** * Datastoreへの接続 * * @param data */ public static void connectDatastore(RunData rundata) { try { ServletContext servletContext = ((JetspeedRunData) rundata).getServletContext(); String privateKeyFile = servletContext.getRealPath("/WEB-INF/conf/" + PRIVATE_KEY_FILE); DatastoreOptions.Builder optionsfromEnv = DatastoreHelper.getOptionsfromEnv(); Credential newCredential = DatastoreHelper.getServiceAccountCredential(ACCOUNT, privateKeyFile); optionsfromEnv.credential(newCredential); datastore = DatastoreFactory.get().create( optionsfromEnv.dataset(PROJECT_ID).build()); } catch (GeneralSecurityException ex) { logger.error("Error", ex); } catch (IOException ex) { logger.error("Error", ex); } catch (Exception ex) { logger.error("Error", ex); } }

ログイン / 新規登録してコメントする