0

I'm exploring the possibilities of using the Google Forms API to create Forms dynamically from my Node Express service.

After some trail and error I'm able to do a basic conversion of assessments from another system into Google forms.

But now I want to manually change the created forms and I don't know how I can access these. It's created using a service account. Can I give permissions to email addresses or something?

2
  • Are you working with Service accounts and Google Workspace? Also the forms you created with the service accounts do you have their respective ID? Commented Sep 5, 2022 at 21:26
  • I am working with a service account. I do have a formId but if I access the form with my gmail account, I don't have access. Im not working with google workspace Commented Sep 6, 2022 at 7:30

1 Answer 1

1

Accessing the Form

If you are not using Google Workspace you would need to manually share the file with the Gmail account.

Depending on which Version of Drive API you are using. You would need to use:

permissions:create

or

permissions:insert

This will allow you to create an option to directly share the file owned by the service account to another user with access to the Drive UI.

There is also a guide on how to utilize the "permission" for Drive V3 with a sample code for Node, it might give you an insight on how to follow it up:

/**
 * Batch permission modification
 * @param{string} fileId file ID
 * @param{string} targetUserEmail username
 * @param{string} targetDomainName domain
 * @return{list} permission id
 * */
async function shareFile(fileId, targetUserEmail, targetDomainName) {
  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  // Get credentials and build service
  // TODO (developer) - Use appropriate auth mechanism for your app
  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/drive',
  });
  const service = google.drive({version: 'v3', auth});
  const permissionIds = [];

  const permissions = [
    {
      type: 'user',
      role: 'writer',
      emailAddress: targetUserEmail, // '[email protected]',
    },
    {
      type: 'domain',
      role: 'writer',
      domain: targetDomainName, // 'example.com',
    },
  ];
  // Note: Client library does not currently support HTTP batch
  // requests. When possible, use batched requests when inserting
  // multiple permissions on the same item. For this sample,
  // permissions are inserted serially.
  for (const permission of permissions) {
    try {
      const result = await service.permissions.create({
        resource: permission,
        fileId: fileId,
        fields: 'id',
      });
      permissionIds.push(result.data.id);
      console.log(`Inserted permission id: ${result.data.id}`);
    } catch (err) {
      // TODO(developer): Handle failed permissions
      console.error(err);
    }
  }
  return permissionIds;
}

Reference

2
  • Thanks! Will try and accept as solved if its works. Commented Sep 13, 2022 at 8:08
  • Sounds good. With the ID of the Drive file should allow you to add permissions if you authenticated with your service account Commented Sep 13, 2022 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.