Mendeley Python SDK中的身份验证问题 [英] Authentication issue in mendeley Python SDK
本文介绍了Mendeley Python SDK中的身份验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从此处阅读Mendeley文档.我正在尝试从控制台中获取数据,我正在使用教程
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)
现在我不明白在最后一行代码中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
推荐答案
我能够使用下面的代码进行试验并使其完全自动化.无需用户干预
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': 'xxxx@gmail.com',
'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)
最后一行显示[<mendeley.models.files.File object at 0x1115b5400>]
,表示可以访问
The last line prints [<mendeley.models.files.File object at 0x1115b5400>]
which means the access if working
这篇关于Mendeley Python SDK中的身份验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文