[英]Call an API on AWS API Gateway using Cognito Credentials from Android
I am trying to use AWS
API
Gateway generated android SDK
to call an API
using amazon Cognito
for authentication made using AWS
API
Gateway.我正在尝试使用
AWS
API
Gateway 生成的android SDK
来调用API
使用amazon Cognito
进行使用AWS
API
Gateway 进行的身份验证。 Cant understand how to call the api's.无法理解如何调用 api。 Any pointers on how to make an API call from android using the generated API Gateway
Android SDK
.有关如何使用生成的 API Gateway
Android SDK
从 android 进行 API 调用的任何指示。 Have went through a lot of articles.看了很多文章。
It might seem a bit confusing to start with.开始可能看起来有点混乱。 But it is similar to a normal SDK we use.
但它类似于我们使用的普通 SDK。 Let's say you have a user post in your API, and you want to create a user with few parameters like name, email, phone number according to the json your API's accept, your code will look something like
假设您的 API 中有一个用户帖子,并且您想根据您的 API 接受的 json 创建一个包含姓名、电子邮件、电话号码等参数的用户,您的代码将类似于
You create an instance of your SDK with:您可以使用以下命令创建 SDK 实例:
credentialsProvider = new CognitoCachingCredentialsProvider(
context,
"identityPoolID",
AMAZON_COGNITO_REGION
);
factory = new ApiClientFactory().credentialsProvider(credentialsProvider)
.endpoint("<endpoint>");
INSTANCE.client = INSTANCE.factory.build(<class>.class);
You create an object of the User with:您创建一个用户对象:
UserModel output = new UserModel();
output.setFirstName("something");
output.setEmail("abc@xyc.com");
And then you make a user post with:然后你发布一个用户帖子:
client.usersPost(output);
Hope it's clear.希望很清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.