使用Javascript从浏览器调用带有参数的Google Cloud Functions

时间:2017-09-28 19:04:23

标签: javascript google-cloud-platform google-cloud-functions

我正在尝试将一些活动从移动网站分批流式传输到BigQuery,我试图通过参数触发Google Cloud功能。

我已经达到了启动脚本的程度,但如何使用param调用Google Cloud功能?

<script src="https://apis.google.com/js/api.js"></script>
<script>
function start() {
  // 2. Initialize the JavaScript client library.
  gapi.client.init({
    'apiKey': 'YOUR_API_KEY',
    // Your API key will be automatically added to the Discovery Document URLs.
    'discoveryDocs': ['https://people.googleapis.com/$discovery/rest'],
    // clientId and scope are optional if auth is not required.
    'clientId': 'YOUR_WEB_CLIENT_ID.apps.googleusercontent.com',
    'scope': 'profile',
  }).then(function() {
    // 3. Initialize and make the API request.
    return gapi.client.people.people.get({
      'resourceName': 'people/me',
      'requestMask.includeField': 'person.names'
    });
  }).then(function(response) {
    console.log(response.result);
  }, function(reason) {
    console.log('Error: ' + reason.result.error.message);
  });
};
// 1. Load the JavaScript client library.
gapi.load('client', start);
</script>

1 个答案:

答案 0 :(得分:0)

我希望你找到了解决方案......但我通常会这样做:

var getPeople = gapi.client.people.people.get({
    'resourceName': 'people/me',
    'requestMask.includeField': 'person.names'
});

getPeople.execute(function(response) {
    console.log(response.result);
}, function(reason) {
    console.log('Error: ' + reason.result.error.message);
});