{"meta":{"title":"排查 OAuth 应用访问令牌请求错误","intro":"为访问令牌交换代码时，可能会发生另外一组错误。 这些响应的格式由您传递的接受标头确定。","product":"应用","breadcrumbs":[{"href":"/zh/apps","title":"应用"},{"href":"/zh/apps/oauth-apps","title":"OAuth 应用"},{"href":"/zh/apps/oauth-apps/maintaining-oauth-apps","title":"维护 OAuth 应用"},{"href":"/zh/apps/oauth-apps/maintaining-oauth-apps/troubleshooting-oauth-app-access-token-request-errors","title":"令牌请求疑难解答"}],"documentType":"article"},"body":"# 排查 OAuth 应用访问令牌请求错误\n\n为访问令牌交换代码时，可能会发生另外一组错误。 这些响应的格式由您传递的接受标头确定。\n\n> \\[!NOTE]\n> 这些示例仅显示 JSON 响应。\n\n## 客户端凭据不正确\n\n如果你传递的客户端\\_ID 和/或客户端\\_密码不正确，将收到此错误响应。\n\n```json\n{\n  \"error\": \"incorrect_client_credentials\",\n  \"error_description\": \"The client_id and/or client_secret passed are incorrect.\",\n  \"error_uri\": \"/apps/managing-oauth-apps/troubleshooting-oauth-app-access-token-request-errors/#incorrect-client-credentials\"\n}\n```\n\n若要解决此错误，请确保您拥有适用于 OAuth app 的正确凭据。 仔细检查 `client_id` 和 `client_secret`，确保它们正确无误，并被正确传递给 GitHub。\n\n## 重定向 URI 不匹配\n\n如果你提供的 `redirect_uri` 与在 OAuth app 中注册的内容不匹配，你将收到以下错误消息：\n\n```json\n{\n  \"error\": \"redirect_uri_mismatch\",\n  \"error_description\": \"The redirect_uri MUST match the registered callback URL for this application.\",\n  \"error_uri\": \"/apps/managing-oauth-apps/troubleshooting-authorization-request-errors/#redirect-uri-mismatch2\"\n}\n```\n\n要更正此错误，请提供一个与你注册的 URL 匹配的 `redirect_uri`，或者忽略此参数以使用在应用程序中注册的默认 URL。\n\n## 验证码错误\n\n如果你传递的验证码不正确、已过期或与你在第一次授权请求中收到的验证码不匹配，将收到此错误。\n\n```json\n{\n  \"error\": \"bad_verification_code\",\n  \"error_description\": \"The code passed is incorrect or expired.\",\n  \"error_uri\": \"/apps/managing-oauth-apps/troubleshooting-oauth-app-access-token-request-errors/#bad-verification-code\"\n}\n```\n\n若要解决此错误，请再次启动 [OAuth 授权过程](/zh/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps)，并获取新代码。\n\n## 未经验证的用户电子邮件\n\n如果尝试为其生成用户访问令牌的用户未验证其主要电子邮件地址 GitHub，则会收到此错误。\n\n```json\n{\n  \"error\": \"unverified_user_email\",\n  \"error_description\": \"The user must have a verified primary email.\",\n  \"error_uri\": \"/apps/managing-oauth-apps/troubleshooting-oauth-app-access-token-request-errors/#unverified_user_email\"\n}\n```\n\n若要解决此错误，请提示用户验证其 GitHub 帐户上的主要电子邮件地址。 有关详细信息，请参阅 [验证电子邮件地址](/zh/account-and-profile/how-tos/email-preferences/verifying-your-email-address)。"}