14

Is it possible to share a GCP printer with a Google API service account (https://developers.google.com/accounts/docs/OAuth2ServiceAccount)?

I tried to share the printer with the client email address (id@developer.gserviceaccount.com), but the printer is not shown in the response to the API call /search. Calling /submit leads to an error (User has no access)

Chris
  • 1,133
  • 7
  • 14

2 Answers2

25

As you yourself shared the printer with the service account, we can assume you know the "Printer ID" of the printer to which the service account has been invited.

Have the service account call the /processinvite request, with these (mandatory) parameters:

  • printerid = the-known-printer-id
  • accept = true

After that, the printer will appear in /search

Happy printing!

jr997
  • 457
  • 5
  • 5
  • 2
    This works and your answer is the only place on the web this is "documented". – Kyle MacFarlane Apr 08 '16 at 01:22
  • 1
    Can confirm--this works perfectly! 1) From the Cloud Print dashboard, share the printer with the service account. 2) Have the service account POST `/processinvite` -- the easiest way to get the printer ID is to copy it from the URL of the dashboard page (`https://www.google.com/cloudprint#printers/`) – Wolfgang Jul 01 '16 at 20:40
  • 2
    I added this command to a library with example code for the process at https://github.com/io7/GoogleCloudPrint – mstrange Dec 17 '16 at 02:38
  • Thank you. I can't even begin to imagine how you found this undocumented trick. – Carl Jun 25 '17 at 17:09
  • i was going to rip my hair out until i found this answer. 3 days of pain. oh my god! – nikk wong Dec 09 '18 at 11:29
  • I can't test this, I've shared a printer through API (/share) with a test user to service account and then /processinvite with the service account returns success, but the printers does not apperar nor /search or /printer. – Jean Paul Rumeau Mar 01 '19 at 23:33
17

I believe you are encountering the "is pending" problem.
Namely, you did share your printer with the id@developer.gserviceaccount.com account but the other user (in this case id@developer.gserviceaccount.com) has to accept the invitation to share the printer.

You can check this by issuing the /print request and you will see an

"is_pending": true

element in the access section for your user (id@developer.gserviceaccount.com) in this case.

Needless to say that accounts that have this element set to true cannot print - hence the "User is not authorized." message.
I know no way to accept the invitation for the given service account however there is a workaround:

  1. You can create a private google group with an account that can accept shared printers (e.g. your gmail account).
  2. Then you add the service account ("id@developer.gserviceaccount.com") to the group et voila. You can print with the service account ;).

When you share the printer you must share it with the google group (use the group's email address which you can find somewhere in the group management console) and the group manager (e.g. your gmail account) must accept the invitation for the whole group.

More info on how to create the group can be found here.
I have tried this with a GAE service account and it works. If you need any clarification do not hesitate to ask. Good luck.

Draken
  • 3,134
  • 13
  • 34
  • 54
dexter
  • 530
  • 7
  • 19