모든 http/rest 호출에 대해 안드로이드 앱에 retrofit2
을 사용합니다. 이제 Amazon AWS API Gateway으로 생성 된 API를 호출해야합니다.안드로이드에서 retrofit2를 통해 Cognito 자격 증명으로 API 게이트웨이를 호출하는 방법은 무엇입니까?
나는 클라이언트 코드는 API 게이트웨이 콘솔을 던져 요청 구축하기 위해 클래스를 ApiClientFactory
을 사용하여 생성해야하는 AWS 문서 say : 나는 retrofit
때와 같은 API를 정의하고 싶습니다 대신
ApiClientFactory factory = new ApiClientFactory();
// Use CognitoCachingCredentialsProvider to provide AWS credentials
// for the ApiClientFactory
AWSCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
context, // activity context
"identityPoolId", // Cognito identity pool id
Regions.US_EAST_1 // region of Cognito identity pool
};
factory.credentialsProvider(credentialsProvider);
// Create an instance of your SDK (this should come from the generated code).
final MyApiClient client = factory.build(MyApiClient.class);
// Invoke a method (e.g., 'parentPath1Get(param1,body)') exposed by your SDK.
// Here the method's return type is OriginalModel.
OriginalModel output = client.parentPath1Get(param1,body);
// You also have access to your API's models.
OriginalModel myModel = new OriginalModel();
myModel.setStreetAddress(streetAddress);
myModel.setCity(city);
myModel.setState(state);
myModel.setStreetNumber(streetNumber);
myModel.setNested(nested);
myModel.setPoBox(poBox);
를 : 내가 작성한 인터페이스로 RxJava, OkHttp 등에 연결하십시오.
질문 : 어떻게 Cognito Identity Provider로 갱신 요청을 할 수 있습니까?
AWS SDK를 직접 사용하고 Rx Observables에서 직접 처리했습니다. 잭 콘 (Jack Kohn)의 대답은 잘못이 아니지만 실제로는 답변이 아니며 스스로 구현하려는 경우 올바른 방향을 가리키고 있습니다. –
그래서 나는 API 게이트웨이와 안드로이드를 연결하려고 노력하고있다. 그러나 어떻게 또는 어디서 얻었 는가/클래스'MyApiClient'를 만들었나? – TheQ
이름은 서비스에 따라 다릅니다. theres 발전기/API 게이트웨이 웹 콘솔에서 내보낼 수 있습니다. 나는이 방법을 사용하지 않았다. 덕분에 –