Google API 提供免费的 API 指标,涵盖 API 使用情况的常见方面,包括请求数、错误、延迟、请求和响应大小。这些指标会针对应用和位置提供精细的维度信息。开发者可以发现异常的 API 使用情况,并确定潜在的根本原因。例如,错误代码高于 400 可能表示最近更新的应用遇到了一些逻辑错误,而较高的请求和响应大小可能会导致应用性能降低。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eThis guide helps application developers troubleshoot their use of Google APIs and Google Cloud APIs.\u003c/p\u003e\n"],["\u003cp\u003eUtilizing \u003ccode\u003ecurl -v\u003c/code\u003e for initial testing of Google APIs is recommended to identify and resolve issues before application development.\u003c/p\u003e\n"],["\u003cp\u003eGoogle APIs offer metrics for monitoring API usage, providing insights into request counts, errors, latencies, and data sizes to help discover and address abnormal usage.\u003c/p\u003e\n"],["\u003cp\u003eClient-side logging of API errors is highly encouraged for security and privacy and is essential for detailed troubleshooting, as Google APIs generally do not provide server-side logs to developers.\u003c/p\u003e\n"],["\u003cp\u003eUnderstanding API error codes, messages, and details is key to effectively resolving issues, with error codes enabling high-level error handling and messages and details aiding in diagnosing application logic flaws.\u003c/p\u003e\n"]]],[],null,["# Troubleshooting API usage\n\nThis page provides application developers an overview of how to troubleshoot\ntheir usage of Google APIs and Google Cloud APIs.\n\nBackground\n----------\n\nGoogle APIs are networked APIs provided by Google services. Applications\ncan access Google APIs via JSON HTTP and gRPC from different environments.\nWe recommend developers to use Google-provided client libraries in their\napplications. These libraries implement common boilerplate logic, such as\nauthentication and list pagination, which greatly reduce development\noverhead and common mistakes.\n\nFor more information, see\n[Client Libraries Explained](/apis/docs/client-libraries-explained)\n\nGetting started\n---------------\n\nIf you are new to Google APIs, you should follow the\n[Getting Started](/apis/docs/getting-started) page to complete the\npreparation steps for your application. You should first use the `curl -v`\ncommand to send test requests to Google APIs that you want to use.\nIt lets you experiment with Google APIs without writing any code.\nYou can often resolve many issues before you start real application\ndevelopment.\n\nFor more information, see [Getting Started](/apis/docs/getting-started).\n\nTroubleshooting using metrics\n-----------------------------\n\nGoogle APIs provide free API metrics that cover common aspects of API usage,\nincluding request counts, errors, latencies, request and response sizes. They\nprovide fine-grained dimensions in terms of applications and locations.\nDevelopers can discover abnormal API usage, and identify potential\nroot causes. For example, higher 400 errors can mean a recently\nupdated application has some logical bugs, or higher request and response\nsizes can cause slower application performance.\n\nFor more information, see [Monitoring API usage](/apis/docs/monitoring).\n\nTroubleshooting using logs\n--------------------------\n\nFor security and privacy reasons, Google APIs generally don't provide API logs\nto application developers. We highly recommend application developers log\nAPI errors on the client side. You can either log the errors to a local storage\nor to a remote logging API, such as [Cloud Logging API](/logging).\n\nLogs typically contain more information about errors than metrics, such as\nerror messages and error details. They are extremely useful and often\nnecessary to troubleshoot API errors. When developers notice any issue\nwith their API usage, they can query the logs to find error messages and\nerror details, and use the information to resolve the errors or contact\nthe support.\n\n### Cloud Audit Logs\n\nFor security sensitive activities, Google Cloud products may generate audit\nlogs that contain detailed information of the activities. They are a great\nsource of information for troubleshooting your usage of Google Cloud APIs.\nFor example, [VPC Service Controls](/vpc-service-controls) dry run feature\ngenerates audit logs for administrators to evaluate the upcoming policy changes.\n\nFor more information, see [Cloud Audit Logs](/logging/docs/audit).\n\nResolving errors\n----------------\n\nIf you have issues with your Google API usage and you have found the\ncorresponding metrics and logs, you can follow API Design Guide\n[Errors](/apis/design/errors) page to resolve the errors.\n\nIn general, each API error has 3 pieces of information: error code, error\nmessage, and error details:\n\n- The error code lets applications handle the error at the higher level, such as retry after `503` errors or re-authenticate users after `401` errors.\n- The error message lets application developers understand the error and\n fix their application logic.\n\n | **Warning:** Do not code against the error messages; they are subject to change without notice.\n- The error details contain additional information the applications can use\n to handle the error programmatically.\n\nFor more information, see the [Errors](/apis/design/errors) page."]]