'Why Linkedin API return 404 when i try to get email address

I try to get email address of logged user from Linkedin API so I do GET request on: https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~)) with Authorization header Bearer access_token. But I get 404 with response

{"serviceErrorCode":0,"message":"Resource null does not exist","status":404}

Endpoint with profile data /v2/me work correctly. What i do wrong?

Sample code not refactored yet, only for get response and request log. Do not be influenced by the names of the variables:

   webClient = WebClient.builder()
            .baseUrl("https://api.linkedin.com")
            .clientConnector(new ReactorClientHttpConnector(HttpClient.create().wiretap(this.getClass().getCanonicalName(), LogLevel.INFO, AdvancedByteBufFormat.TEXTUAL)))
            .build();
        webClient.get()
            .uri(uriBuilder -> uriBuilder.path("/v2/me").build())
            .header("Authorization", "Bearer " + facebook.getAccessToken())
            .retrieve()
            .bodyToMono(GoogleProfile.class)
            .log()
            .block();
        webClient.get()
            .uri(uriBuilder -> uriBuilder.path("v2/emailAddress?q=members&projection=(elements*(handle~))").build())
            .header("Authorization", "Bearer " + facebook.getAccessToken())
            .retrieve()
            .bodyToMono(GoogleProfile.class)
            .log()
            .block();

And my client code:

    const redirectUri = 'http://localhost:8082/login/linkedin/callback';
    const scope = 'r_liteprofile r_emailaddress';
    const clientId = 'client_code';
    const responseType = 'code';

    const linkedinLoginAction = () => {
        window.open(`https://www.linkedin.com/oauth/v2/authorization?client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=${responseType}`)
    }

Maybe it's some problem with user profile configuration linked with email address privacy policy or something?



Solution 1:[1]

I fix it by added queryParams by method not directly in url :

webClient.get()
            .uri(uriBuilder -> uriBuilder.path("v2/emailAddress")
                .queryParam("q", "members")
                .queryParam("projection", "(elements*(handle~))").build())
            .header("Authorization", "Bearer " + facebook.getAccessToken())
            .retrieve()
            .bodyToMono(GoogleProfile.class)
            .log()
            .block();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tomDev93