5

I have integrated aws amplify into and android app by following https://docs.amplify.aws/lib/q/platform/android in my mac book pro.

Now I check-out the same project into another machine mac mini. and trying to run.

I am getting this error, not sure how to fix it.

AmplifyException {message=Failure performing sync query to AppSync: [GraphQLResponse.Error{message='You are not authorized to make this call.'

tried, amplify pull, amplify configure, amplify init. but none are able to resolve this issue.

thanks in advance

4

3 回答 3

9

最初,您将在 Network 选项卡中看到您的 graphql 由于授权而失败。

“我的情况是 App Sync API 密钥已过期。 – Freddie Jun 26”

这就是答案,转到 Appsync / Settings / API 密钥。

您将看到“红色”键。这意味着它已经过期了。

您只需要创建一个新密钥。然后在名称下的 aws-exports.js 中为 appsync api 替换这个新密钥aws_appsync_apiKey

如果您已解决此问题,我将把它留在这里,以便其他人可以看到。

于 2021-08-29T06:45:30.080 回答
1

啊! 好消息,您可以简单地编辑日期(无需制作新日期)。

只是默认是一周。

转到您的普通、完整、普通的 AWS 控制台。转到“aws appsync”。

然后 ..

在此处输入图像描述

于 2021-11-09T14:39:15.393 回答
0

如果您的令牌已过期(这里我说的是一个最长 365 天且已过期的令牌)并且您有机会使用 amplify 将您的应用程序发布到 AWS,您将需要向应用程序添加新令牌(只需更改在 awsexports 中是不够的)。为此,您必须:

  1. 找到该文件amplify/backend/<your_app_name>/parameters.json并在其中添加两行(这可能只是CreateAPIKey,但我只测试了在这个github 问题中找到的一种方法并且它有效)。
   "APIKeyExpirationEpoch": -1,
   "CreateAPIKey": -1
  1. 运行amplify push。这应该删除旧令牌。但是您最好自己在 Appsync/settings/api 键中检查它。如果您那里没有令牌,那么您就可以开始了。

  2. 返回parameters.json文件并删除我们的参数(APIKeyExpirationEpochCreateAPIKey)。

  3. 运行amplify update api。选择你的 api(我的是 Graphql)。选择更新身份验证设置。选择您的默认授权方法(我的 Api 密钥)。输入您的 api 密钥的描述并为您的 api 密钥添加 ttl(默认为 7,因此我建议更改此)。不要配置其他身份验证类型。 在此处输入图像描述

  4. 您应该在最后收到成功消息。现在做amplify push。过了一会儿,命令应该返回成功消息,你就可以开始了。要仔细检查,您可以在 appsync 中验证令牌。应该只有一个令牌。此外,您可以检查应该保存新令牌的标头中的 api 调用x-api-key值。

于 2021-11-28T13:21:01.150 回答