Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Cloud Print API #73

Closed
carlganz opened this issue Jun 24, 2017 · 4 comments
Closed

Issues with Cloud Print API #73

carlganz opened this issue Jun 24, 2017 · 4 comments

Comments

@carlganz
Copy link

carlganz commented Jun 24, 2017

Hello,

Thank you for this wonderful package. I am having a small issue that I would like to share. After creating a service account and saving the JSON file, I get an error with this code:

library(googleAuthR)
options("googleAuthR.scopes.selected" = c("https://www.googleapis.com/auth/cloudprint"))
options(googleAuthR.verbose = 1)
options("googleAuthR.ok_content_types"= c(getOption("googleAuthR.ok_content_types"),
                                          "text/plain"))

x <- gar_auth_service("path/to/my.json", scope = c("https://www.googleapis.com/auth/cloudprint"))

list_printers <- gar_api_generator("https://www.google.com/cloudprint/search")
list_printers()

Issue is appending / at the end of the URL gives a 404 error. Would it be possible to add a parameter to gar_api_generator for appending the / which defaults to TRUE? This would allow for edge cases like mine to opt-out of the feature.

I also find that httr:::print.response generates an error each time the result of list_printers() is printed, but it doesn't affect anything so far as I can tell.

Kind Regards,
Carl

@MarkEdmondson1234
Copy link
Owner

MarkEdmondson1234 commented Jun 25, 2017

Hi Carl, that was easy enough to add, so its in now on GitHub version. Give it a go:

library(googleAuthR)
options("googleAuthR.scopes.selected" = c("https://www.googleapis.com/auth/cloudprint"))
options(googleAuthR.verbose = 1)
options("googleAuthR.ok_content_types"= c(getOption("googleAuthR.ok_content_types"),
                                          "text/plain"))

x <- gar_auth_service("path/to/my.json", scope = c("https://www.googleapis.com/auth/cloudprint"))

list_printers <- gar_api_generator("https://www.google.com/cloudprint/search", 
                                   checkTrailingSlash = FALSE)
list_printers()

MarkEdmondson1234 added a commit that referenced this issue Jun 25, 2017
@carlganz
Copy link
Author

Thanks Mark. I was able to get a semi-functioning package started here.

I am able to print small amounts of text using GET, but I have not been successful printing more substantial documents using POST. If you have any idea what I am doing wrong here I would greatly appreciate some guidance.

Kind Regards,
Carl

@MarkEdmondson1234
Copy link
Owner

I think when using POST, you will need to send the data via a body request, so something like (untested)

gcp_submit <- function(printerid,
                       title,
                       ticket = NULL,
                       content,
                       contentType = NULL,
                       tag = NULL,
                       http_header = c("GET", "POST")) {
  http_header <- match.arg(http_header)
  f <- googleAuthR::gar_api_generator(
    "https://www.google.com/cloudprint/submit",
    http_header = http_header,
    data_parse_function = function(x) {
      x$success
    },
    pars_args = list(
      printerid = '',
      title = '',
      ticket = jsonlite::toJSON(list(
        version = jsonlite::unbox("1.0"),
        print = c()
      ), auto_unbox = FALSE),
      content = '',
      contentType = '',
      tag = ''
    ),
    customConfig = list(
      # https://developers.google.com/cloud-print/docs/pythonCode#multipart-form-data
      encode = "multipart"
    ),
    checkTrailingSlash = FALSE
  )
 
  switch(http_header,
    GET = f( etc... ),
    POST = f(the_body = content)  ## when POST, add the data as body
   )
}

@carlganz
Copy link
Author

Thanks I was able to get it to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants