Skip to content

获取个人信息

步骤一:引入 OAuthApp 库

<!-- data-appid 属性替换为你的 OAuthApp 应用的 ID -->
<script id="appcore" src="https://www.oauthapp.com/lib/sdk/oauthapp.1.9.8.js" data-appid="2"></script>

在 HTML 文件的头部,我们首先需要引入 OAuthApp 库。其中 data-appid 属性需要替换为你的 OAuthApp 应用的 ID。

步骤二:页面结构

<p>结果</p>
<div id="result"></div>

步骤三:调用方法

oauthapp.allReady().then(function () {
    oauthapp.profile().then(function (res) {

    });
});

这段代码使用 allReady() 方法等待所有的 OAuthApp 插件加载完毕并初始化后,调用 profile() 方法获取当前登录用户的用户信息。在 then() 方法中,可以对返回的用户信息进行操作。

步骤四:测试结果

$('#result').text(JSON.stringify(res));

完整代码示例

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>profile</title>
    <!-- data-appid 属性替换为你的 OAuthApp 应用的 ID -->
    <script id="appcore" src="https://www.oauthapp.com/lib/sdk/oauthapp.1.9.8.js" data-appid="2"></script>
</head>
<body>
    <p>结果</p>
    <div id="result"></div>
    <script>
        oauthapp.allReady().then(function () {
            oauthapp.profile().then(function (res) {
                $('#result').text(JSON.stringify(res));
            });
        });
    </script>
</body>
</html>