Python Mendeley SDK API returns error in authentication

283 views Asked by At

I have a mendeley account which I am using from their online version. I created a userid and client secret, saved it in config.yml file from and using it to authenticate. I am using the below code available on their website

import yaml
from mendeley import Mendeley

with open('config.yml') as f:
    config = yaml.load(f)

REDIRECT_URI = 'http://localhost:5000/oauth'

mendeley = Mendeley(config['clientId'], config['clientSecret'], REDIRECT_URI)
auth = mendeley.start_client_credentials_flow()
session = auth.authenticate()

This code works fine and I got not errors. But when I am trying to access data using the commands in the example it throws error. For example

>> print (session.profiles.me.display_name)

mendeley.exception.MendeleyApiException: The Mendeley API returned an error (status: 400, message: No userid found in auth token)

>> for document in session.documents.iter():
    print document.title

mendeley.exception.MendeleyApiException: The Mendeley API returned an error (status: 403, message: Access to this document is not allowed)

I am stuck here and do not know how to access the data or articles I have on mendeley fom its API. Any help will be highly appreciated.

1

There are 1 answers

0
DieterDP On

You are using the Client Credentials flow (a term from OAuth). Quoting from the docs:

This flow does not require the user to log in. However, it only provides access to a limited set of resources (the read-only Mendeley Catalog of crowd sourced documents).

The two calls from your questions are private (user) information, and will therefor fail.

On the other hand, the following should work:

print session.catalog.by_identifier(doi='10.1371/journal.pmed.0020124', view='stats').reader_count

If you want to access private information, you will need users to log in. This question should help.