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

Google Drive API推送通知接收失败求助:本地端点配置后无法接收通知但Postman调用正常

Troubleshooting Google Drive API Push Notifications Not Reaching Local Endpoint

Let's break down the possible issues and fixes for your scenario, since you've confirmed the endpoint works with Postman but not with Google's push notifications:

1. Verify Push Subscription Configuration

  • Double-check that the address property in your notification channel exactly matches your active ngrok HTTPS URL (including the /notifications path). Ngrok URLs change every time you restart the service—if you've restarted ngrok since creating the subscription, you must update the channel's address to the new URL.
  • Ensure your subscription targets the correct Google Sheets file (confirm the resourceId or file ID is accurate) and that the service account/credentials used to create the subscription have sufficient permissions (e.g., drive.file or drive.readonly scope for the target file).
  • Check if you enabled payload in the subscription settings. If set to true, Google sends a JSON payload with the notification—your current code doesn't process the payload, but this shouldn't block delivery unless your endpoint rejects non-form-data requests (though Postman testing suggests this isn't the case).

2. Inspect Ngrok Request Logs

When running ngrok, keep an eye on the terminal output. If there are no entries for requests from Google, that means Google isn't attempting to send notifications to your endpoint (pointing to a subscription configuration issue). If you see requests but they return errors (e.g., 403, 500), note the status code and debug accordingly.

3. Handle Google's Subscription Validation Request

Google sends a sync type notification when you first create a subscription to verify your endpoint is valid. Your current code only processes notifications where x-goog-changed contains "content", so this validation request might be ignored (even though you return 200). Modify your code to log all incoming requests to confirm if Google is reaching your endpoint:

@PostMapping("/notifications")
@AnonymousAllowed
public ResponseEntity<Void> webHookHandler(HttpServletRequest request) {
    // Log all headers to debug incoming requests
    log.info("Incoming request URL: {}", request.getRequestURL());
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String header = headerNames.nextElement();
        log.info("{}: {}", header, request.getHeader(header));
    }

    String headerGoogChanged = request.getHeader("x-goog-changed");
    if (!ObjectUtils.isEmpty(headerGoogChanged) && headerGoogChanged.contains("content")) {
        service.parseDashboardAndSave(view.getGrid(), sheetsService.readSheetValuesBatch());
        sheetsService.writeSheetValuesBatch(service.getKeyWordDashboards());
        log.info("Content change notification processed");
    }
    return ResponseEntity.ok().build();
}

This will help you confirm if Google is sending any requests to your endpoint at all.

4. Check Google Cloud Project Settings

  • Ensure the Google Drive API is enabled in your Google Cloud Console project.
  • Review Cloud Logging for your project (under "Logging > Logs Explorer") for errors related to push notifications—common issues include permission denials or invalid endpoint URLs.
  • Confirm your service account has been granted access to the target Google Sheets file (share the file with the service account's email address if needed).

5. Rule Out SSL/Endpoint Access Issues

While Google no longer requires manual domain verification, your endpoint must be publicly accessible over HTTPS (which ngrok provides). Ensure there are no firewalls or local network rules blocking incoming requests to your ngrok URL. You can also test the ngrok URL from a different network to confirm accessibility.


内容的提问来源于stack exchange,提问作者Александр Хворостенко

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 23:28:15