是否可以通过gapi javascript客户端访问Google Cloud Datastore API?

时间:2013-07-08 23:27:15

标签: google-api-js-client google-cloud-datastore

有没有人有任何使用gapi javascript客户端访问google云数据存储区API的示例代码? https://developers.google.com/datastore/docs/overview

1 个答案:

答案 0 :(得分:1)

var clientId = '<YOUR_CLIENT_ID>';
var datasetId = '<YOUR_DATASET_ID>';
var scopes = 'https://www.googleapis.com/auth/datastore \
https://www.googleapis.com/auth/userinfo.email';
gapi.auth.authorize(
    {client_id: clientId, scope: scopes, immediate: false},
    function(authResult) {
      if (authResult && !authResult.error) {
        gapi.client.load('datastore', 'v1beta1', function() {
          gapi.client.datastore.datasets.beginTransaction({
            'datasetId': datasetId
          }).execute(function(resp) {
            console.log(resp);
          });
        });
      }
    });

请注意,由于Google Cloud Datastore没有ACL支持,因此javascript客户端将拥有对整个数据集的完全读/写权限。