问题
I see this Access to Outlook RestAPI from an Outlook web Add-in question but nothing about attachment there.
I success to make outlook rest API request from my add-in follow https://dev.office.com/docs/add-ins/outlook/use-rest-api?product=outlook this tutorial . For example I success to get some message details), but I have 2 problems:
I can't add attachment with outlook rest API call to message. I try to make call with the itemId like here:
https://outlook.office.com/api/v2.0/me/messages/" + itemId +"/attachments
The error I get is:
{"error":{"code":"ErrorAccessDenied","message":"The api you are trying to access does not support item scoped OAuth."}}
I try to change permissions(ReadWriteMailbox/ReadWriteItem) on manifest but nothing help..
Sometimes the call of Office.context.mailbox.getCallbackTokenAsync({ isRest: true }, function().... function work and return access token and sometimes return error , I don't know also what the reason. The error I get sometimes is:
OSF.DDA.AsyncResult error:OSF.DDA.Error status:"failed"
Hope you could help me , thanks all!!
回答1:
On #1, the error indicates that the token you have is scoped to just the current item. The REST API cannot use this kind of token for modifying attachments, so you get that error. The correct way that this should work is that you specify ReadWriteMailbox
in your add-in manifest, and then the token you get back should be a mailbox-scoped token. However, there is currently a bug with desktop Outlook's handling of getCallbackTokenAsync
that causes it to incorrectly still return an item-scoped token. That bug has been fixed but the update hasn't been publicly pushed yet.
If you want to check this, copy the token you get back and head over to https://jwt.io/. Paste it in the "Encoded" box and check the payload. If you see "ver": "Exchange.Callback.V1"
it's the item-scoped token. If you see "ver": "Exchange.Callback.V2"
it's the mailbox-scoped one.
On #2, I have no idea. It would be helpful if you could get a Fiddler trace on your Outlook client machine that catches the add-in making the token request.
来源:https://stackoverflow.com/questions/42420073/cant-add-attachment-to-message-in-outlook-add-in-using-outlook-rest-api