简体   繁体   English

在调用操作 api 时获得 403-PERMISSION_DENIED

[英]Getting 403- PERMISSION_DENIED on calling actions api

I was trying to send push notification to google assistant by calling actions api " https://actions.googleapis.com/v2/conversations:send ".我试图通过调用操作 api“ https://actions.googleapis.com/v2/conversations:send ”来向谷歌助手发送推送通知。 I'm getting 403-The caller does not have permission error.我收到 403 - 调用者没有权限错误。

I followed the steps mentioned in the push notification documentation.我按照推送通知文档中提到的步骤进行操作。 " https://developers.google.com/actions/assistant/updates/notifications#java ". https://developers.google.com/actions/assistant/updates/notifications#java ”。

Created service account key and assigned the Role as Project Owner.创建服务帐号密钥并将角色分配为项目所有者。

    String token = getAccessToken();
    HttpPost request = new HttpPost("https://actions.googleapis.com/v2/conversations:send");
    request.setHeader("Content-type", "application/json");
    request.setHeader("Authorization", "Bearer " + token);
    StringEntity entity = new StringEntity("{\n" +
            "  \"customPushMessage\": {\n" +
            "    \"target\": {\n" +
            "      \"userId\": \"id of user\",\n" +
            "      \"intent\": \"intent name\",\n" +
            "      \"locale\": \"en-US\"\n" +
            "    },\n" +
            "    \"userNotification\": {\n" +
            "      \"title\": \"title\",\n" +
            "      \"text\": \"test msg\"\n" +
            "    }\n" +
            "  }\n" +
            "}");
    entity.setContentType(ContentType.APPLICATION_JSON.getMimeType());
    request.setEntity(entity);
    HttpClient httpClient = HttpClientBuilder.create().build();
    HttpResponse res = httpClient.execute(request);
 private String getAccessToken() throws IOException {
    AccessToken token = loadCredentials().refreshAccessToken();
    return token.getTokenValue();
}
 private ServiceAccountCredentials loadCredentials() throws IOException {
    String actionsApiServiceAccountFile =
            this.getClass().getClassLoader().getResource("/serviceaccountkey.json").getFile();
    InputStream actionsApiServiceAccount = new FileInputStream(actionsApiServiceAccountFile);
    ServiceAccountCredentials serviceAccountCredentials =
            ServiceAccountCredentials.fromStream(actionsApiServiceAccount);
    return (ServiceAccountCredentials)
            serviceAccountCredentials.createScoped(
                    Collections.singleton(
                            "https://www.googleapis.com/auth/actions.fulfillment.conversation"));
}    

Expected actions api to send push notification to the user.向用户发送推送通知的预期操作 api。

But getting the error:但得到错误:

{ "error": { "code": 403, "message": "The caller does not have permission", "status": "PERMISSION_DENIED" } } { "error": { "code": 403, "message": "调用方没有权限", "status": "PERMISSION_DENIED" } }

请参阅用 Java 编写的AoG 更新和推送通知代码示例,了解如何通过 Actions API 使用 Java 客户端库正确发送推送通知。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BigQuery Write API Java - PERMISSION_DENIED:资源上的权限“TABLES_UPDATE_DATA”被拒绝 - BigQuery Write API Java - PERMISSION_DENIED: Permission 'TABLES_UPDATE_DATA' denied on resource Google Speech API返回PERMISSION_DENIED,该请求无法与客户端项目标识 - Google Speech API returns PERMISSION_DENIED the request cannot be identified with a client project 谷歌表 API(带有 java)显示“消息”:“请求的身份验证范围不足。”,“状态”:“PERMISSION_DENIED” - Google sheet API (with java) is showing “message” : “Request had insufficient authentication scopes.”, “status” : “PERMISSION_DENIED” PERMISSION_DENIED:权限 TABLES_UPDATE_DATA - PERMISSION_DENIED: Permission TABLES_UPDATE_DATA BigQuery JsonStreamWriter 有时会抛出 PERMISSION_DENIED 错误 - BigQuery JsonStreamWriter sometimes throw PERMISSION_DENIED error 由于安全规则,Firestore上出现“ PERMISSION_DENIED”问题 - Problem of “PERMISSION_DENIED” on Firestore get due to security rule Google Cloud Translate V3 Java - PERMISSION_DENIED:Cloud IAM 权限“cloudtranslate.generalModels.predict”被拒绝 - Google Cloud Translate V3 Java - PERMISSION_DENIED: Cloud IAM permission 'cloudtranslate.generalModels.predict' denied 获取SecurityException:Java中的权限被拒绝 - Getting a SecurityException: Permission denied in java Android:调用https://maps.googleapis.com/maps/api/geocode/xml时获取HTTP 403禁止 - Android: Getting HTTP 403 Forbidden upon calling https://maps.googleapis.com/maps/api/geocode/xml Java在调用Web服务时收到错误403 - java getting error 403 on calling web service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM