不确定我在这里做错了什么我正在尝试使用Python脚本更新OneNote页面,我可以很好地对其进行检索我正在使用设备身份验证流程,并且在获得令牌时发送的范围是这些
scopes=[
"Notes.Read",
"Notes.Read.All",
"Notes.ReadWrite",
]
我可以使用此页面阅读页面
headers={'Authorization': 'Bearer ' + token}
content_end_point='https://graph.microsoft.com/v1.0/users/{my-user-id}/onenote/pages/{page-id}/content?includeIDs=true'
content=requests.get(content_end_point,headers=headers)
print(content.text)
现在我使用上面确认为可访问的链接来更新同一页面
headers={'Authorization': 'Bearer ' + token,'Content-Type': 'application/json' }
content_end_point='https://graph.microsoft.com/v1.0/me/onenote/notebooks/pages/{page-id}/content'
data= {
'target':'body',
'action':'prepend',
'content':'<p data-id="first-child">New paragraph as first child in the first div</p>'
}
result=requests.patch(endpoint,headers=headers,json=data)
print(result.text)
并且我收到此错误
{
"error": {
"code": "UnknownError",
"message": "{\r\n \"Message\": \"No HTTP resource was found that matches the request URI 'https://www.onenote.com/api/v1.0/users('[email protected]')/notes'.\"\r\n}",
"innerError": {
"request-id": "334a17e2-09f2-4744-900b-29b325dd1e64",
"date": "2020-05-19T03:08:51"
}
}
}
更新:尝试创建新页面会导致相同类型的错误Update2:有趣的是,回复[当我尝试使用MS Graph API时,返回了有关OneNote API的信息。我去了Portal.azure.com,我对MS Graph进行了更多的撰写(它是只读的以及上面提到的其他权限已应用于OneNote。)这并没有改变任何内容我将稍等一下,看看这是否是权限传播错误,并解决了该问题。 如果我仍然看到OneNote消息,这意味着这里有问题,应该是MS Graph回到我身边
Update2:以下是OneNote和MSGraph的权限(作用域)
scopes=[
"Notes.Read",
"Notes.Read.All",
"Notes.ReadWrite",
"Notes.ReadWrite.All",
"Notes.Create",
"Notes.ReadWrite.CreatedByApp"
]
但是我仍然收到有关OneNote无法找到URI的相同错误消息
更新3
headers={'Authorization': 'Bearer ' + token,'Content-Type': 'application/json' }
content_end_point='https://graph.microsoft.com/v1.0/me/onenote/pages/{page-id}/content'
data= {
'target':'body',
'action':'prepend',
'content':'<p data-id="first-child">New paragraph as first child in the first div</p>'
}
result=requests.patch(endpoint,headers=headers,json=data)
print(result.text)
以上仍然给我同样的错误。抱歉,最初的粘贴是由于多次尝试找到一种使之起作用的方法而导致的。我知道该页面,然后尝试了
{
"error": {
"code": "UnknownError",
"message": "{\r\n \"Message\": \"No HTTP resource was found that matches the request URI 'https://www.onenote.com/api/v1.0/users('[email protected]')/notes'.\"\r\n}",
"innerError": {
"request-id": "bcc11791-d847-46af-b6ee-e3fd060c4ca0",
"date": "2020-05-20T01:01:50"
}
}
}
[不确定是否相关,但是当我尝试使用MS Graph Explorer时,无法使用“创建页面”示例。该示例应该加载一个模板,在该模板中我应该替换一个ID .....并添加页面的内容。没有发生!
您的权限看起来正确。但是,您尝试使用的端点不正确。 / onenote和/ pages之间没有“ notebooks”段。使用此链接作为正确端点URL的参考:https://docs.microsoft.com/en-us/graph/api/page-update?view=graph-rest-1.0&tabs=http
这是我的愚蠢案例我正在定义