Paradoxis
Paradoxis

Reputation: 4708

Google cloud printing via PHP

I'm trying to make an app that automatically prints a PDF after it has been generated for the client. (by his request) I got a cloud printer up and running which works perfectly fine if I try to use it with something like chrome.

All libaries for PHP are extremely outdated (up to 4 years old) and most of them are completely broken or provide little to no documentation on how to use them, and trying to use google's own documentation is even more of a nightmare

The best I could come up with was using this libary: yasirsiddiqui/php-google-cloud-print, mostly because it was the only one I could actually figure out how to use it.

However when I use this to submit a print job the owner of the account (me) gets a warning email that someone suspicious is trying to log into their account and it has been blocked.

Does anyone know if there is a (working) library to do this with, or if there is a command line alternative (preferred) that I could use system() or exec() with?

Note: I have 0% knowledge of python, and using JavaScript to submit these jobs is NOT an option because end users are not allowed to alter the document.


Update [2015/09/08]: For some reason Google doesn't allow printing via some accounts even when using OAuth2, a quick hack to fix this was by simply creating an entirely new account and printing with that.

Upvotes: 4

Views: 8315

Answers (2)

Yasir Siddiqui
Yasir Siddiqui

Reputation: 435

I have updated code to use Google OAuth2 and now there will not be any issues related to account blocked or security risk etc. Here is url of updated code https://github.com/yasirsiddiqui/php-google-cloud-print

Upvotes: 8

Mazzy
Mazzy

Reputation: 327

I've never heard of Google Cloud printing but it appears to just be a simple REST API, in which case you do not need a library to interact with it, just use something like CURL. Here is a page which lets you test out the various interfaces they offer:

https://www.google.com/cloudprint/simulate.html

A dry parameter list is available here for submitting jobs:

https://developers.google.com/cloud-print/docs/appInterfaces#submit

I would just use CURL to post my requests and not worry about over engineering some huge class especially when you don't need every available option in the API. You should look at the Python examples- I know that you do not have much experience with Python but the HTTP headers you set to login, etc, will be the same as in PHP:

login.putheader('content-type', 'application/x-www-form-urlencoded')

Is the same as:

$request_headers[] = 'content-type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);`

I did find an API here, but it is behind a paywall so I cannot attest to it's quality- if you're doing this for a client though it may be worth the money and effort saved to check it out:

http://www.phpgang.com/how-to-configure-google-cloud-api-in-php_288.html

Upvotes: 2

Related Questions