2

I am trying to create tables for a google map in the maps engine. I have added the service account to the access list in the mapsengine admin panel for the map and gave it "can edit" permissions. I also gave it edit permissions in the developer console for the project.

this is where I am sending off for the access token which is sending back a token:

    var googleapis = require('googleapis');
    function connect() {
        var authClient = new googleapis.auth.JWT(
            '216755859529-1s2o9qofhd9ea65ang9clpd1936ldfcr@developer.gserviceaccount.com',
            '../bin/googleoauth2.pem',
            'notasecret',
            ['https://www.googleapis.com/auth/mapsengine'],
            // User to impersonate (leave empty if no impersonation needed)
            ''
        );

        authClient.authorize(function(err, tokens) {
             if (err) {
             console.log(err);
             return;
        }
         else {
             console.log(tokens);
        }

        googleapis.discover('mapsengine', 'v1').execute(function (err, client) {
             if (err) {
                 console.log('Problem during the client discovery.', err);
                 return;
             }
             createNewTable();
             client.mapsengine.tables.create(mapengine_table_body).withAuthClient(authClient).execute(function (err, response) {
            if (err) {
                console.log(err);
                return;
            } else {
                console.log(response);
                return;
            }
        });

    });
  });
}

This is where I am creating the table and sending it:

function createNewTable() {

   mapengine_table_body = {
  "projectId": projectID,
  "name": "World Famous Mountains",
  "description": "A partial list of famous mountains in the world.",
  "draftAccessList": "Map Editors",
  "tags": [
    "mountain",
    "high places"
  ],
  "schema": {
    "columns": [
      {
        "name": "geometry",
        "type": "points"
      },
      {
        "name": "mountain_name",
        "type": "string"
      },
      {
        "name": "height",
        "type": "integer"
      }
    ]
  }
 }
}
function start() {

    'use strict';
    var pck, program;

    pck = require('../package.json');
    program = require('commander');

    program
        .version(pck.version)
        .option('-r, --run', 'Run')
        .parse(process.argv);

    console.log('running:');
         if (program.run) {
         connect();
    }
}

The ProjectId I am getting from the url when viewing the project. I have looked through as much documentation as I can find, but I haven't been able to figure this one out. Thanks.

Mark McDonald
  • 7,571
  • 6
  • 46
  • 53
user3734990
  • 150
  • 1
  • 7
  • 1
    What's the error you're seeing (and where)? And what libraries are you using for the authentication & request steps? Your code doesn't look like the [Google JS library](https://developers.google.com/api-client-library/javascript/reference/referencedocs), have you tried them? – Mark McDonald Jun 15 '14 at 22:53
  • @MarkMcDonald I actually changed the code to use the google node library. I am still getting the error in the cli when I log the response. I am able to GET and log the response and it will list the projects or maps that I have previously made, but it will not let me create a table. I am getting a "Insufficient permissions for this action" I am editing my original post to show the new code. – user3734990 Jun 16 '14 at 13:43

1 Answers1

0

Without your error response I can't give you an exact answer, but here are a couple of pointers.

  1. Check the contents of err in the execute block. The API will return something in err.errors that should explain what the problem is, if it's occurring on the API side.
  2. It's not clear what the scope of the mapengine_table_body variable is, try logging it right in the connect() call right after calling createNewTable() to make sure you have the actual data.
  3. The third argument in the googleapis.auth.JWT constructor (at least according to this) is not the key password, it's an alternative way to provide the actual key inline (as opposed to using the file location in argument #2).
  4. Project IDs in Maps Engine may look like large numbers but treating them as large numbers in JavaScript will very likely result in rounding, meaning that you give the API a different number than is in your code. To prevent this, make sure your project ID is "quoted", so that its treated as a string.

Hopefully something here helps! If not, please share the output from suggestion #1.

Mark McDonald
  • 7,571
  • 6
  • 46
  • 53