私は、Google クラウド プリントを Web アプリケーションに統合して、生成後にクライアントが PDF ファイルをプリンタに送信できるようにする作業を行っています。
Google 開発者サイトで入手可能なすべてのドキュメントを調べましたが、これまでテスト アプリケーションを Google 印刷 Web サービスに接続することができませんでした。
現在のプロセスは次のとおりです。
- アプリケーションは、ユーザーと Google からユーザーのプリンターを使用/管理する許可を取得します (Google API を使用)。
- これにより、Google から 0Auth 認証トークンが返されます。
- そのトークンは、サーバー上で新しい印刷ジョブを作成しようとするために、新しい http 要求を作成するために使用されます (このサービスで使用できるものを確認できなかったため、API を使用していません)。
- リクエストを送信した後、アプリケーションはレスポンス ストリームを読み取ろうとし、毎回 403 エラーが発生します。確かに、Google のヘッダー形式に従っていることは確かです。
要するに、私が求めているのは次のとおりです。
- このような Google Web サービスとやり取りするときによくあるつまずきはありますか?
- Google プリント Web サービスとの通信プロセスを簡素化する API はありますか。
- 検討したいGoogleプリントの代替品はありますか.
ありがとう。
private void SendPrintJob()
{
string googlePrintURL = @"https://www.google.com/cloudprint/submit";
Classes.pos_CloudPrintObject print = new Classes.pos_CloudPrintObject();
print.printerid = "28a52678-43ef-6592-e32c-255e7220cb8a";
print.title = "Test Print";
print.populateTicket();
print.content = "Hello World";
//googlePrintURL += "?printerid=" + print.printerid;
//googlePrintURL += "&title=" + print.title;
//googlePrintURL += "&ticket={}&content=" + print.content;
string queryString =
"printerid=" + print.printerid +
"&capabilities=" +
"&contentType=" + "txt" +
"&title=" + print.title +
"&content=" + print.content;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.google.com/cloudprint/submit");
request.Method = "POST";
string code = Request["code"];
request.Headers.Add("Authorization", "OAuth " + code);
request.Headers.Add("Accept-Encoding", "ASCII");
//request.Headers.Add("Accept-Charset", "ISO-8859-1");
request.Headers.Add("X-CloudPrint-Proxy", "TestProj");
request.ContentType = ("application/x-www-form-urlencoded");
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] bytePost = encoder.GetBytes(JsonConvert.SerializeObject(print));
request.ContentLength = bytePost.Length;
using (Stream writeStream = request.GetRequestStream())
{
writeStream.Write(bytePost, 0, bytePost.Length);
}
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
//Prints out status of upload into debugger (But can be altered to return string instead)
using (response)
{
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
{
String result = reader.ReadToEnd();
System.Diagnostics.Debug.WriteLine(result);
}
}
}
}
catch (Exception ex)
{
throw (ex);
}
}