Git Product home page Git Product logo

mendeley-api-python-catalog-example's Introduction

Mendeley API Python Catalog Example

This is a simple example of an application that consumes the Mendeley API, using the Python SDK.

For more information on the API, see the developer portal.

About the application

The application is a simple command-line script that retrieves the number of Mendeley users that have read a document with a given DOI. It uses the client credentials flow, meaning that users don't have to log in to Mendeley to use the application.

Prerequisites

Register your client at the developer portal. This will give you a client ID and secret. (You will not get very far without these!)

How to install

  1. Install Python and Pip.

  2. Run the following command to install dependencies:

     pip install -r requirements.txt
    

How to run

Insert your API keys with one of these methods:

  • Config file method: Rename the config.yml.example file to config.yml, and fill in your client ID and secret in this file.
  • Environment variable method: Set the MENDELEY_CLIENT_ID and MENDELEY_CLIENT_SECRET environment variables in your shell context to the appropriate values.

Now run the example:

	python mendeley-catalog.py [DOI you want to look up]

Build status

Travis CI

mendeley-api-python-catalog-example's People

Contributors

aglet avatar matt-thomson avatar themasterchef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mendeley-api-python-catalog-example's Issues

Missing access token parameter error

Hi,

I'm using python 2.7 and the config file method with the packages used in the requirements file. I'm coming across the following error:

File "mendeley-catalog.py", line 23, in
session = mendeley.start_client_credentials_flow().authenticate()
File "/home/rafael/anaconda2/envs/mendeley/lib/python2.7/site-packages/mendeley/auth.py", line 31, in authenticate
token = oauth.fetch_token(self.token_url, auth=self.auth, scope=['all'])
File "/home/rafael/anaconda2/envs/mendeley/lib/python2.7/site-packages/requests_oauthlib/oauth2_session.py", line 199, in fetch_token
self._client.parse_request_body_response(r.text, scope=self.scope)
File "/home/rafael/anaconda2/envs/mendeley/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 409, in parse_request_body_response
self.token = parse_token_response(body, scope=scope)
File "/home/rafael/anaconda2/envs/mendeley/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 376, in parse_token_response
validate_token_parameters(params)
File "/home/rafael/anaconda2/envs/mendeley/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 386, in validate_token_parameters
raise MissingTokenError(description="Missing access token parameter.")
oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter.

Could you please advise on how to solve this? Thank you.

InvalidClientError following example

I cloned the repo.
I created app:

id=1055
key=provided secret here
redirect_uri=http://localhost:5000/oauth

I updated the config.yaml with above key and secret.

I ran the script and got the below.

ubuntu@ip-10-63-175-117:~/mendeley-api-python-catalog-example$ python mendeley-catalog.py
Traceback (most recent call last):
  File "mendeley-catalog.py", line 8, in 
    session = mendeley.start_client_credentials_flow().authenticate()
  File "/usr/local/lib/python2.7/dist-packages/mendeley/auth.py", line 32, in authenticate
    token = self.oauth.fetch_token(token_url, auth=auth, scope=['all'])
  File "/usr/local/lib/python2.7/dist-packages/requests_oauthlib/oauth2_session.py", line 180, in fetch_token
    self._client.parse_request_body_response(r.text, scope=self.scope)
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/oauth2/rfc6749/clients/backend_application.py", line 156, in parse_request_body_response
    self.token = parse_token_response(body, scope=scope)
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/oauth2/rfc6749/parameters.py", line 303, in parse_token_response
    validate_token_parameters(params, scope)
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/oauth2/rfc6749/parameters.py", line 310, in validate_token_parameters
    raise_from_error(params.get('error'), params)
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/oauth2/rfc6749/errors.py", line 239, in raise_from_error
    raise cls(**kwargs)
oauthlib.oauth2.rfc6749.errors.InvalidClientError

Please help.

Thanks

mendeley.exception.MendeleyException: Catalog document not found following example

I have fetched git repo and made "pip install -r requirements.txt" and checked that everything has installed.

silpol@hostname:/tmp/mendeley-api-python-catalog-example$ pip install -r requirements.txt -U
Requirement already up-to-date: PyYAML==3.11 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 1))
Requirement already up-to-date: argparse==1.2.1 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 2))
Requirement already up-to-date: arrow==0.5.0 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 3))
Requirement already up-to-date: certifi==14.05.14 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 4))
Requirement already up-to-date: future==0.14.3 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 5))
Requirement already up-to-date: memoized-property==1.0.2 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 6))
Requirement already up-to-date: mendeley==0.3.0 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 7))
Requirement already up-to-date: oauthlib==0.7.2 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 8))
Requirement already up-to-date: python-dateutil==2.4.0 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 9))
Requirement already up-to-date: requests==2.5.1 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 10))
Requirement already up-to-date: requests-oauthlib==0.4.2 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 11))
Requirement already up-to-date: six==1.9.0 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 12))
Requirement already up-to-date: wsgiref==0.1.2 in /usr/lib/python2.7 (from -r requirements.txt (line 13))

Then I re-used OAuth credentials from previous test. Then launched script as described in readme. It looks like OAuth passed just fine. Then I get prompt

Enter a DOI:

for which I provide DOI for existing document 10.1145/1815961.1816021

and then I get exception

silpol@hostname:/tmp/mendeley-api-python-catalog-example$ python mendeley-catalog.py 
Enter a DOI: 10.1145/1815961.1816021
Traceback (most recent call last):
  File "mendeley-catalog.py", line 12, in <module>
    doc = session.catalog.by_identifier(doi=doi, view='stats')
  File "/usr/local/lib/python2.7/dist-packages/mendeley/resources/catalog.py", line 47, in by_identifier
    raise MendeleyException('Catalog document not found')
mendeley.exception.MendeleyException: Catalog document not found

Is this expected behaviour or malfunction?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.