Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The example does not set the FieldMask property that is required to make the call... #11017

Open
vedranstanic82 opened this issue Jul 14, 2024 · 3 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: docs Improvement to the documentation for an API.

Comments

@vedranstanic82
Copy link

The readme says use this:

com.google.maps
google-maps-places
0.17.0

This code throws an error:
try (PlacesClient placesClient = PlacesClient.create()) {
GetPlaceRequest request =
GetPlaceRequest.newBuilder()
.setName(PlaceName.of("ChIJzU97rT_XZUcRJ1yuz1AvTP0").toString())
.setLanguageCode("languageCode-2092349083")
.setRegionCode("regionCode-1991004415")
// .setSessionToken("sessionToken-696552189")
.build();
ApiFuture future = placesClient.getPlaceCallable().futureCall(request);
// Do something.
Place response = future.get();

        log.debug("Found this place: " + response.getDisplayName());

aused by: com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: FieldMask is a required parameter. See https://cloud.google.com/apis/docs/system-parameters on how to provide it. As an example, you can set the header 'X-Goog-FieldMask' to value 'displayName', 'id' to ask for the display name and the place id of a place. You can also set the value to '*' in manual testing to get all the available response fields.

at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:92)
at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:41)
at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:86)
at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:66)
at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:97)
at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:84)
at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1130)
at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:31)
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1298)
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:1059)
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:809)
at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:568)
at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:538)
at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
at com.google.api.gax.grpc.ChannelPool$ReleasingClientCall$1.onClose(ChannelPool.java:570)
at io.grpc.internal.DelayedClientCall$DelayedListener$3.run(DelayedClientCall.java:489)
at io.grpc.internal.DelayedClientCall$DelayedListener.delayOrExecute(DelayedClientCall.java:453)
at io.grpc.internal.DelayedClientCall$DelayedListener.onClose(DelayedClientCall.java:486)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:574)
at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:72)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:742)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:723)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
... 1 common frames omitted

Caused by: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: FieldMask is a required parameter. See https://cloud.google.com/apis/docs/system-parameters on how to provide it. As an example, you can set the header 'X-Goog-FieldMask' to value 'displayName', 'id' to ask for the display name and the place id of a place. You can also set the value to '*' in manual testing to get all the available response fields.

at io.grpc.Status.asRuntimeException(Status.java:533)
... 17 common frames omitted

2024-07-14T22:56:51.591+02:00 WARN 13279 --- [ XNIO-2 task-2] .m.m.a.ExceptionHandlerExceptionResolver : Re

So the library is not compatible with the server code it seems and there is no way to set the FieldMask. Or at least give us an example of how to set this required field.

@mpeddada1 mpeddada1 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: docs Improvement to the documentation for an API. labels Jul 18, 2024
@dimaloop
Copy link

dimaloop commented Aug 5, 2024

any updates here? how to set up "field" for GetPlaceRequest?

@cherfia
Copy link

cherfia commented Aug 30, 2024

@vedranstanic82 @dimaloop After digging through the codebase for hours. I came up with a solution. You can set the field mask in the header provider when you’re setting up PlacesSettings for your client. Here's a Kotlin snippet for Spring Boot, but you can easily adapt it to Java.

import com.google.maps.places.v1.PlacesClient
import com.google.maps.places.v1.PlacesSettings
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class GeoClient {
    @Bean
    fun client(): PlacesClient {
        val placesSettings = PlacesSettings.newBuilder()
            .setHeaderProvider {
                mutableMapOf(
                    "X-Goog-FieldMask" to "*",
                )
            }.build()
        return PlacesClient.create(placesSettings)
    }
}

I hope that helps you!

@docent
Copy link

docent commented Oct 19, 2024

@vedranstanic82 @dimaloop @cherfia There is better way to do it - per request.
val result = client.searchTextCallable().call(request, GrpcCallContext.createDefault().withExtraHeaders( mapOf("X-Goog-FieldMask" to listOf("places.displayName", "places.id"))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: docs Improvement to the documentation for an API.
Projects
None yet
Development

No branches or pull requests

5 participants