简体   繁体   English

使用来自 Android 的 Cognito 凭证调用 AWS API Gateway 上的 API

[英]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.

相关问题 如何通过Android上的retrofit2使用Cognito Credentials调用API网关? - How to call API Gateway with Cognito Credentials through retrofit2 on Android? Android上的AWS Api Gateway和Cognito-错误401 - AWS Api Gateway and Cognito on Android - Error 401 尝试使用生成的SDK从Android进行“ Hello World” AWS API Gateway GET API调用 - Trying to make a “Hello World” AWS API Gateway GET API call from Android using Generated SDK 如何使用API​​ Gateway AWS调用Web服务 - How to call Webservice using API Gateway AWS 如何在android中添加aws签名并调用aws api网关 - how to add aws signature in android and call aws api gateway 如何让AWS Cognito登录/注销在Android上与AWS API Gateway一起正常运行? - How can I get AWS Cognito login/logout to work properly with AWS API Gateway on Android? 使用 AWS Amplify 和 Android 通过 Cognito 对 REST API 进行身份验证 - Authenticating a REST API with Cognito using AWS Amplify & Android 来自Android应用程序的AWS API Gateway REST DELETE方法调用在模拟器中运行正常,但无法在设备上运行? - AWS API Gateway REST DELETE method call from android app working fine in emulator but not working from device? 如何使用AWS API Gateway在Android中调用GET方法? - How to call a GET method in android with aws api gateway? 无需 AWS 凭证即可从 Android 登录 AWS Cognito - AWS Cognito signin from Android without AWS credentials
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM