Search code examples
mendeley

Mendeley Implicit auth type not returning full data


This question relates to the Mendeley API. http://dev.mendeley.com/

When using the implicit auth type: http://dev.mendeley.com/reference/topics/authorization_overview.html

I seem to only receive a subset of data for a given document. For example, the 'websites' field seems to not come through even when it is populated.

I am only experiencing this issue using the implicit auth type and not other auth types.

Are any other Mendeley API users experiencing this? It seems like a bug.


Solution

  • Certain fields get returned depending on the document view that you specify. This was implemented to be able to support the needs of multiple clients e.g. mobile clients require smaller datasets than larger web clients

    Please read - http://dev.mendeley.com/methods/#document-views

    You need to specify 'view=bib' on your endpoint call.

    Here is a very crude worked example just using Java

    @Test
    public void testImplicitGrantFlow() {
    
        String random = RandomStringUtils.random(5);
    
        String query = String.format(
                "?client_id=%s&redirect_uri=%s&response_type=token&scope=all&state=%s", IMPLICIT_GRANT_FLOW_CLIENT_ID, "http://localhost:5000/callback", random);
    
        ClientResponse authorise = jerseyClient.resource(AUTH_URL + query)
                .accept(MediaType.APPLICATION_JSON)
                .get(ClientResponse.class);
    
        assertThat(authorise.getStatus()).isEqualTo(200);
    
        ClientResponse postFormDataResponse = jerseyClient.resource(AUTH_URL + query)
                .entity("[email protected]&password=spuds", MediaType.APPLICATION_FORM_URLENCODED_TYPE)
                .accept(MediaType.APPLICATION_JSON)
                .post(ClientResponse.class);
        assertThat(postFormDataResponse.getStatus()).isEqualTo(302);
    
        String queryString = postFormDataResponse.getHeaders().get("Location").get(0);
    
        Matcher matcher = ACCESS_TOKEN_REGEX.matcher(queryString);
        matcher.find();
        String accessToken = matcher.group(1);
    
        matcher = STATE_REGEX.matcher(queryString);
        matcher.find();
        String state = matcher.group(1);
    
        assertNotNull(accessToken);
        assertThat(queryString).contains(accessToken);
    
        assertNotNull(state);
        assertThat(queryString).contains(state);
    
        ClientResponse response = jerseyClient.resource(OAuthBaseClass.DOCUMENTS_URL)
                .header("Authorization", "Bearer " + accessToken)
                .get(ClientResponse.class);
        assertThat(response.getStatus()).isEqualTo(200);
    
        List<Document> documents = response.getEntity(new GenericType<List<Document>>() {
        });
        assertThat(documents.size()).isGreaterThan(0);
    
        ListIterator<Document> documentListIterator = documents.listIterator();
        while (documentListIterator.hasNext()) {
            Document next = documentListIterator.next();
              System.out.println(next.getTitle());
              System.out.println(next.getWebsites());
    
        }
    
    }