问题
I make the following REST GET request:
https://graph.microsoft.com/v1.0/me/onenote/notebooks
I get the following response:
{
    "error": {
        "code": "30108",
        "message": "The OneDriveForBusiness for this user account cannot be retrieved.",
        "innerError": {
            "request-id": "25926552-3157-483a-bbcd-41a7105cd531",
            "date": "2017-07-22T18:46:07"
        }
    }
}
I do not have a One Drive For Business account. Do I really need one to access the OneNote API?
Thanks.
回答1:
Yes. In order to use the API (to access OneNote data), you must have a OneDrive (whether personal/consumer or business/Office 365) - since the OneNote cloud data is actually stored in OneDrive/SharePoint. If you have an Office 365 account, you can try going to https://portal.office.com and then click in the left-hand "waffle" button, and click OneDrive which should create your own personal OneDrive for Business.
Please take a look at https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/onenote for more details.
Also, if you are just trying out the API you could use Graph Explorer. It has some saved/sample queries that you can try. (Under Sample Queries, click show more samples and toggle the OneNote switch).
Hope this helps,
回答2:
Here how I solved it in my Azure function by switching to authentication with Microsoft account and using the classic OneNote Rest API.
var request = require('request');
module.exports = function (context, req) {
    var microsoftAccountAccessToken = req.headers['x-ms-token-microsoftaccount-access-token'];
    context.log( "Microsoft Account Access Token: " + microsoftAccountAccessToken );
    request(
        {
            url: 'https://www.onenote.com/api/v1.0/me/notes/notebooks',
            method: "GET",
            headers: {
                'Authorization': 'Bearer ' + microsoftAccountAccessToken
            },
        },
        function( error, response, body )
        {
            if (!error && response.statusCode === 200) {
                context.log(body);
                context.res = {
                    body: body
                };
                context.done();
            }
            else {
                context.log("error: " + error)
                context.log("response.statusCode: " + response.statusCode)
                context.log("response.statusText: " + response.statusText)
                context.res = {
                    body: response.statusText
                };
                context.done();
            }
        }
    );
};
回答3:
https://docs.microsoft.com/en-us/graph/onenote-error-codes#30108
The user's personal OneDrive for Business could not be retrieved. The following table lists some possible causes.
- The user's personal site has not been provisioned. The user should open OneDrive for Business and follow any instructions to provision the site. If this fails, they should contact their Office 365 tenant administrator.
- The user's personal site is currently being provisioned. Try the request later.
- The user does not have a valid OneDrive for Business license. The user should contact their Office 365 tenant administrator.
- A network issue prevented the request from being successfully sent.
回答4:
I tried many ways and finally I used the method mentioned here: https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/how-to/onenote-auth
The auth server is login.live.com, the above page provides two methods: code and token. Both could use. After auth and get the token, I can call Graph API with that token.
Code method is simpler to demonstrate. First, open this in browser:
https://login.live.com/oauth20_authorize.srf
  ?response_type=token
  &client_id={client_id}
  &redirect_uri={redirect_uri}
  &scope={scope}
Then, after login an account, it will callback. Just copy the access_token in the callback URL. Do:
GET https://graph.microsoft.com/v1.0/me/onenote/pages
Accept: application/json
Authorization: Bearer {access_token}
The pages could be retrieved without 30108 error. These are simple test steps. I implemented in Java, and can get OneNote data through Microsoft's Graph library(com.microsoft.graph:microsoft-graph:1.5.+). As below:
IOnenotePageCollectionPage pages = graphClient.me().onenote().pages().buildRequest().get();
graphClient is IGraphServiceClient. But I implemented the authentication provider through login.live.com.
来源:https://stackoverflow.com/questions/45258173/error-the-onedriveforbusiness-for-this-user-account-cannot-be-retrieved-when