Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authentication issue in mendeley Python SDK

I was reading Mendeley docs from here. I am trying to get data in my console for which I am using the following code from the tutorial

from mendeley import Mendeley

# These values should match the ones supplied when registering your application.
mendeley = Mendeley(client_id, redirect_uri=redirect_uri)

auth = mendeley.start_implicit_grant_flow()

# The user needs to visit this URL, and log in to Mendeley.
login_url = auth.get_login_url()

# After logging in, the user will be redirected to a URL, auth_response.
session = auth.authenticate(auth_response)

Now I don't understand where is auth_response will come from in the last line of code ? Does anybody have any idea ? Thanks

like image 391
muazfaiz Avatar asked Mar 07 '23 09:03

muazfaiz


1 Answers

I was able to experiment with and get it working using below code, fully automated. No user intervention

client_id = 1
client_secret = "XXXXXXXXX"

redirect_uri = "http://localhost:8080/testing"

from mendeley import Mendeley

# These values should match the ones supplied when registering your application.
mendeley = Mendeley(client_id, redirect_uri=redirect_uri)

auth = mendeley.start_implicit_grant_flow()

# The user needs to visit this URL, and log in to Mendeley.
login_url = auth.get_login_url()

import requests

res = requests.post(login_url, allow_redirects = False, data = {
    'username': '[email protected]',
    'password': 'xxxxx'
})

auth_response = res.headers['Location']

# After logging in, the user will be redirected to a URL, auth_response.
session = auth.authenticate(auth_response)

print(session.files.list().items)

The last line prints [<mendeley.models.files.File object at 0x1115b5400>] which means the access if working

like image 102
Tarun Lalwani Avatar answered Mar 19 '23 16:03

Tarun Lalwani