You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel集成Google Cloud Printing报错:用户未授权问题求助

Fixing "User is not authorised" (errorCode:8) with Laravel Google Cloud Print

Hey there, let's tackle this frustrating "User is not authorised" error (errorCode:8) you're hitting with the Laravel Google Cloud Print package. I've worked through similar OAuth authorization issues with Google services before, so here's a step-by-step breakdown to get your print requests working:

1. Verify Your OAuth 2.0 Credentials Setup

  • First, make sure you created an OAuth 2.0 Client ID in the Google Cloud Console (not a service account—this package relies on user-facing OAuth flow).
  • Double-check that the redirect_uri in your Laravel config (config/google-cloud-print.php) matches exactly what you've set in the Google Console. Even tiny differences like HTTP vs HTTPS, or a missing trailing slash, will break authorization.
  • Confirm the Google account you're using hasn't revoked access to your app. You can check this in your Google Account's Security > Third-party apps with account access section.

2. Ensure Config File Parameters Are Correct

  • Open config/google-cloud-print.php and verify that client_id, client_secret, and redirect_uri are all copied correctly from your Google Cloud Console OAuth client details—no typos or extra spaces allowed.
  • After updating the config, clear Laravel's config cache to make sure the new settings are loaded:
    php artisan config:clear
    

3. Re-Trigger the OAuth Authorization Flow

This package requires a valid access token tied to your Google account. If your token expired or wasn't properly stored, you'll get this error:

  • Visit the default authorization route provided by the package: /google/cloud/print/auth (unless you customized it in the config).
  • Log in with the Google account that has access to your target printer, and grant the necessary permissions to your app. This will refresh or store a valid access token for future print requests.

4. Check Printer Access Permissions

  • Log into the Google Cloud Print web interface and confirm the printer ID you're using in your code is associated with your Google account. It should show up in your "My Printers" list, or be a shared printer that you've been granted print access to.
  • If it's a shared printer, make sure the owner hasn't revoked your access rights.

Quick Code Check

Just to rule out a simple mistake, confirm that the printer ID in your code is accurate:

$data = GoogleCloudPrint::asText()
    ->content('This is a test')
    ->printer("YOUR_VALID_PRINTER_ID") // Double-check this ID
    ->marginsInCentimeters(1, 1, 1, 1)
    ->send();
return $data;

If you work through these steps, the authorization error should resolve. Let me know if you hit any snags along the way!

内容的提问来源于stack exchange,提问作者Jishad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:27:29