yasirsiddiqui / php-google-cloud-print

PHP class to print documents using Google Cloud Print with OAuth2 authorization
91 stars 42 forks source link

offline access and example not working. #28

Closed emildd closed 4 years ago

emildd commented 7 years ago

I just access offline access and exampe.php and output like this

Fatal error: Uncaught exception 'Exception' with message 'Please first login to Google' in /Applications/XAMPP/xamppfiles/htdocs/cloudprint/GoogleCloudPrint.php:121 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/cloudprint/example.php(29): GoogleCloudPrint->getPrinters() #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/cloudprint/GoogleCloudPrint.php on line 121

viniciuszanovelli commented 7 years ago

Very same here!

viniciuszanovelli commented 7 years ago

@emildd I've found a workaround for this issue that worked for me at least:

  1. Create/insert a file named pdf.pdf at the very same folder of the solution;

  2. Update getAccessToken method in GoogleCloudPrint.php (line 100) inserting the following lines at the very beginning of the method (before any other code already in it):

    $authheaders = array("Authorization: Bearer ".$post_fields['code']);
    $this->httpRequest->setHeaders($authheaders);
  3. Make sure you have access_type = 'offline' in Config.php file ($offlineAccessConfig, line 44);

  4. Run offlineAccess.php and grant the permission to manage your printers (you need to have your Google Cloud Print already set in chrome://devices).

That is it, I hope that helps! :)

yasirsiddiqui commented 7 years ago

The offline access token is only provided on the first authorization from the user. Subsequent authorizations, such as the kind you make while testing an OAuth2 integration, will not return the refresh_token again.

To get offline access token again revoke your app in google developer account and you will again get offline access token only on the first request.

emildd commented 7 years ago

Thank you @znvl it's worked for me.

@yasirsiddiqui for online access, can I use the way at above? and possible to implement at hosting server as a client access?

eelke commented 5 years ago

@yasirsiddiqui It would be helpful if you could write update the README to reflect the need to revoke access, in order to get the offline access token

ruebenacker commented 5 years ago

Use 'approval_prompt' => 'force' in offlineAccessConfig