в моем приложении Lens Studio У меня есть эффект нескольких объектива, который я отображаю через карусель, и из их я посылаю информацию о эффекте выбранного объектива с помощью: < /p>
*
// --- Send metadata to the host application via Remote API ---
if (script.remoteServiceModule && global.RemoteApiRequest) {
var req = global.RemoteApiRequest.create();
// This 'endpoint' name will be used by your Android app to identify the request
req.endpoint = "selectedlens";
req.method = "POST"; // Method is still relevant for the API spec definition
req.body = JSON.stringify({
lensIndex: i,
metadata: selectedMetadata
}); // Send metadata as JSON in the request body
script.remoteServiceModule.performApiRequest(req, function(response) {
if (response.statusCode === 1) { // 1 means success from the host app
try {
var parsedResponse = JSON.parse(response.body);
print("API Response from Host App: " + JSON.stringify(parsedResponse));
// Handle success response from your Android app here
} catch (e) {
print("ERROR: Failed to parse API response from Host App: " + e.message);
}
< /code>
и в моем нативном приложении Android, где моя линза работает совершенно нормально, я пытаюсь получить метаданные с тем же процессом, показанным в документации. < /p>
override fun process(
request: LensesComponent.RemoteApiService.Request,
onResponse: Consumer
): LensesComponent.RemoteApiService.Call {
Log.d("MyLensRemoteApiService", "Received request: ${request.endpointId}")
if (request.endpointId == "selectedlens") {
try {
val requestBodyString = String(request.body, Charsets.UTF_8)
val jsonBody = JSONObject(requestBodyString)
val lensIndex = jsonBody.optInt("lensIndex")
val metadata = jsonBody.optString("metadata")
Log.i("MyLensRemoteApiService", "
Log.i("MyLensRemoteApiService", " Lens Index: $lensIndex")
Log.i("MyLensRemoteApiService", " Metadata: $metadata")
// Access the shared ViewModel instance via the singleton holder
ViewModelHolder.get().postLensApiData(lensIndex, metadata)
// Create a success response body
val responseJson = JSONObject().apply {
put("status", "success")
put("message", "Metadata received by Android app!")
put("receivedLensIndex", lensIndex)
put("receivedMetadata", metadata)
}.toString()
// Send the success response back to the Lens
onResponse.accept(request.toSuccessResponse(body = responseJson.toByteArray(Charsets.UTF_8)))
return LensesComponent.RemoteApiService.Call.Answered
} catch (e: Exception) {
Log.e("MyLensRemoteApiService", "Error processing selectedlens request: ${e.message}", e)
// Create an error response body
val errorJson = JSONObject().apply {
put("status", "error")
put("message", "Failed to process metadata: ${e.message}")
}.toString()
// Send the error response back to the Lens
//onResponse.accept(request.toErrorResponse(body = errorJson.toByteArray(Charsets.UTF_8)))
return LensesComponent.RemoteApiService.Call.Answered
}
}
Log.w("MyLensRemoteApiService", "Ignoring unknown endpoint: ${request.endpointId}")
return LensesComponent.RemoteApiService.Call.Ignored
}
< /code>
Я не получаю журналов, когда получает метаданные при изменении эффекта объектива в нативном приложении,
Я создал удаленный API с помощью веб -приложения My vercel в качестве домена, так как у меня нет никакого другого HTTPS -домена, у меня есть бэкэнд, работающий на экземпляре AWS. Это что -то еще?
, пожалуйста, направьте меня о том, как интегрировать пользовательский API, заранее спасибо < /p>
Подробнее здесь: https://stackoverflow.com/questions/796 ... camera-kit
Мобильная версия