Log.Fatalf("Failed to connect to GCP: %v", err) Log.Printf("Refresh token: %s", refreshToken)Ĭlient, err := gcp.NewGoogleCloudPrint(, refreshToken, refreshToken, proxy, config.ClientID, config.ClientSecret,, ,, jobCh, true) Log.Fatalf("Failed to obtain OAuth token: %v", err) Token, err := config.Exchange(context.Background(), code, oauth2.AccessTypeOffline)
#CONNECT GOOGLE CLOUD PRINTER CODE#
Log.Printf("Follow the link to obtain an auth code: %s", authLink)įmt.Printf("Paste your auth code here: ") If no request token is present, obtain a new oneĪuthLink := config.AuthCodeURL(uuid.New().String(), oauth2.AccessTypeOffline) Log.Fatalf("Failed to obtain OAuth config: %v", err)
Find the proxy in the Advanced Details of your printer at Ĭonfig, err := google.ConfigFromJSON(byte(credJSON), gcp.ScopeCloudPrint) Once you obtained a refresh token make sure to store it in the variable refreshToken.Copy & paste the auth code to the script.Follow the auth link and authorize your OAuth2 client to access Googel Cloud Printers with your Google account.Create an OAuth2 client in your Google Cloud Console as described hereĪnd download its client credentials from the console and copy & past its json content to credJSON in the code snippet below.I ran into the same issue and came up with this two-step solution: Would this help us get the access token, considering firebase is also made by Google? The printing functionality is triggered by a firebase function.
#CONNECT GOOGLE CLOUD PRINTER HOW TO#
I looked at this SO question where OP seems to have been able to get this access token, but I can't understand how he did it.Ĭould someone please explain how to get an access token to use with Google Cloud Printing? Or a good resource which explains how? Single access token can grant varying degrees of access to multipleīut doesn't explain how to obtain this access token. But for step 2, I have no idea what to do.īefore your application can access private data using a GoogleĪPI, it must obtain an access token that grants access to that API. I've gotten so far as to getting my OAuth client ID and secret (step 1 in the OAuth link). But the instructions on how to do that are lacking for a beginner. It seems to me that the authentication should be done with OAuth2. Now, how can I access this account's printers through the API? I have found some documentation here that says that I need to authenticate myself when making requests. I've set up the printers with Google Cloud Printing and it is now accessible from my Google Account. I'm making an app that needs to send printing jobs through Google Cloud Printing to two printers owned by me (i.e., the printers are always the same one and does not belong to the user).