Google Cloud Print - Update

kinlane-productions2kinlane-productions2 Now that you have a Google Cloud Printer registered with the Google Cloud Print (GCP) registry, you will need to keep the status of that printer updated.

After authenticating using Google ClientLogin API, you can update an existing Google Cloud Printer:

<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
// ID of Cloud Printer
$Printer_ID = "";
// Name of Cloud Printer
$Printer_Name = "";
// Description of Cloud Printer
$Printer_Description = "";
// Path to Printer Capabilities in PPD Format
$Printer_Proxy = "";
// Gmail User Email
$G_Email = "";
// Gmail User Password
$G_Pass = "";
//Actually Register the Printer
$client = Zend_Gdata_ClientLogin::getHttpClient($G_Email, $G_Pass, 'cloudprint');
// Get Token and Add Headers
$Client_Login_Token = $client->getClientLoginToken();
$client->setHeaders('Authorization','GoogleLogin auth='.$Client_Login_Token);
$client->setHeaders('X-CloudPrint-Proxy','Mimeo');
//GCP Services - Register
$client->setUri('http://www.google.com/cloudprint/interface/update');
$client->setParameterPost('printer', $Printer_ID);
$client->setParameterPost('printer', $Printer_Name);
$client->setParameterPost('proxy', $Printer_Proxy);
//Pull Capabilities from PPD File
$Capabilities = file_get_contents($Printer_PPD);
$client->setParameterPost('capabilities', $Capabilities);
$client->setParameterPost('defaults', $Capabilities);
$client->setParameterPost('status', 'Online');
$client->setParameterPost('description', $Printer_Description);
$response = $client->request(Zend_Http_Client::POST);
//echo $response;
$PrinterResponse = json_decode($response->getBody());
//var_dump($PrinterResponse);
$Success = $PrinterResponse->success;
//echo "Success: " . $Success . "<br />";
// Printer Information
$Printer = $PrinterResponse->printers[0];
$Printer_ID = $Printer->id;
//echo "Printer ID: " . $Printer_ID . "<br />";
$Printer_Name = $Printer->name;
//echo "Printer Name: " . $Printer_Name . "<br />";
$Printer_Description = $Printer->description;
//echo "Printer Description: " . $Printer_Description . "<br />";
$Printer_Status = $Printer->status;
//echo "Printer Status: " . $Printer_Status . "<br />";
$Printer_CreateTime = $Printer->createTime;
//echo "Printer CreateTime: " . $Printer_CreateTime . "<br />";
?>
view raw GCP - UPDATE hosted with ❤ by GitHub
The Google Cloud Print /list endpoint accepts the following parameter:

  • printerid - Unique printer identification (generated by Google Cloud Print).
  • printer - User readable name of the printer being registered (need not be unique).
  • proxy - Identification of the printer client or proxy (must be unique).
  • capabilities - Printer capabilities (XPS or PPD).
  • defaults - Printer default settings (XPS or PPD).
  • status - Status string of the printer�e.g., Out of Paper, Online, etc.
  • description - Descriptive string about the printer.
  • capsHash - A hash or digest value of the capabilities data. This value is useful, for example, to compare values and check whether the local printer's capabilities have changed.

Here is an example JSON response:
{
"success": true,
"message": "Printer updated successfully."
}

The update service allows you to keep the status and capabilities up to date for a specific cloud printer.