单页应用程序:调用 Web APISingle-page application: Call a web API

我们建议你在调用 Web API 之前调用 acquireTokenSilent 方法获取或续订访问令牌。We recommend that you call the acquireTokenSilent method to acquire or renew an access token before you call a web API. 有了令牌后,就可以调用受保护的 Web API 了。After you have a token, you can call a protected web API.

调用 Web APICall a web API

在 HTTP 请求中使用获得的访问令牌作为持有者令牌来调用任何 Web API,例如 Microsoft Graph API。Use the acquired access token as a bearer in an HTTP request to call any web API, such as Microsoft Graph API. 例如:For example:

    var headers = new Headers();
    var bearer = "Bearer " + access_token;
    headers.append("Authorization", bearer);
    var options = {
         method: "GET",
         headers: headers
    };
    var graphEndpoint = "https://microsoftgraph.chinacloudapi.cn/v1.0/me";

    fetch(graphEndpoint, options)
        .then(function (response) {
             //do something with response
        }

后续步骤Next steps