如何正确访问mendeley API?我无法获取文件的文档id

2024-04-30 03:35:12 发布

您现在位置:Python中文网/ 问答频道 /正文

如何访问mendeley API(文件。文档(id) 谢谢你的帮助

from mendeley import Mendeley
import requests

# I've changed the authentication details of my script (of course)
client_id = ****
client_secret = "**************"
redirect_uri = "********************"

mendeley = Mendeley(client_id, redirect_uri=redirect_uri)

auth = mendeley.start_implicit_grant_flow()

login_url = auth.get_login_url()

res = requests.post(login_url, allow_redirects=False, data={
    'username': '**********',
    'password': '**********'
})

auth_response = res.headers['Location']

session = auth.authenticate(auth_response)

lib = []
for f in session.files.iter():
    try:
        dic = {}
        dic['filehash'] = f.filehash
        dic['mime_type'] = f.mime_type
        dic['file_name'] = f.file_name
        dic['id'] = f.id
        dic['size'] = f.size
        dic['document_id'] = f.document_id  # I can't access this one.
        lib.append(dic)
    except:
        pass

lib应该是一个字典列表。 根据文档,它应该包含有关“文档id”的信息(https://dev.mendeley.com/methods/#files) 如果我尝试包含文档id,则结果为空


Tags: of文档importclientauthidurllib