我尝试使用 Android 应用程序发送短信,smooch-java
但每次都收到错误的请求。
我的代码:
String jwt = "";
try {
jwt = Jwts.builder()
.claim("scope", "app")
.setHeaderParam(KEY_ID, "MY_KEY_ID")
.signWith(
SignatureAlgorithm.HS256,
"MY_SECRET".getBytes("UTF-8")
)
.compact();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (!jwt.isEmpty()) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
ApiKeyAuth apiKeyAuth = (ApiKeyAuth) defaultClient.getAuthentication("jwt");
apiKeyAuth.setApiKey(jwt);
apiKeyAuth.setApiKeyPrefix("Bearer");
ConversationApi apiInstance = new ConversationApi();
String userId = preferencesRepository.getUserId();
MessagePost messagePostBody = new MessagePost();
messagePostBody.setRole("appUser");
messagePostBody.setType(MessagePost.TypeEnum.TEXT);
messagePostBody.setText(message);
try {
PostMessagesResponse result = apiInstance.postMessage(userId, messagePostBody);
Log.d(TAG, "sendMessage: " + result);
} catch (ApiException e) {
Log.e(TAG, "sendMessage:", e);
}
}
错误日志:
io.smooch.client.ApiException: Bad Request
{"error":{"code":"bad_request","description":".items: should not have less than 1 items"}}
来自Docs,这是一条短信,我不需要任何信息,items
但错误提示我至少需要一个item