本模塊提供應(yīng)用帳號(hào)信息的添加、刪除、修改和查詢基礎(chǔ)能力,并支持應(yīng)用間鑒權(quán)和分布式數(shù)據(jù)同步功能。
本模塊首批接口從API version 7開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。
createAppAccountManager(): AppAccountManager
創(chuàng)建應(yīng)用帳號(hào)管理器對(duì)象。
系統(tǒng)能力: SystemCapability.Account.AppAccount
返回值:
類型 | 說明 |
---|---|
AppAccountManager | 應(yīng)用帳號(hào)管理器對(duì)象。 |
示例:
- let appAccountManager = account_appAccount.createAppAccountManager();
createAccount(name: string, callback: AsyncCallback<void>): void;
根據(jù)帳號(hào)名創(chuàng)建應(yīng)用帳號(hào)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)創(chuàng)建成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name. |
12300004 | Account already exists. |
12300007 | The number of accounts reaches the upper limit. |
示例:
- try {
- appAccountManager.createAccount("WangWu", (err) => {
- console.log("createAccount err: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("createAccount err: " + JSON.stringify(err));
- }
createAccount(name: string, options: CreateAccountOptions, callback: AsyncCallback<void>): void
根據(jù)帳號(hào)名和可選項(xiàng)創(chuàng)建應(yīng)用帳號(hào)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
options | 是 | 創(chuàng)建應(yīng)用帳號(hào)的選項(xiàng),可提供自定義數(shù)據(jù),但不建議包含敏感數(shù)據(jù)(如密碼、Token等)。 | |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)創(chuàng)建成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or options. |
12300004 | Account already exists. |
12300007 | The number of accounts reaches the upper limit. |
示例:
- let options = {
- customData: {
- "age": "10"
- }
- }
- try {
- appAccountManager.createAccount("LiSi", options, (err) => {
- if (err) {
- console.log("createAccount failed, error: " + JSON.stringify(err));
- } else {
- console.log("createAccount successfully");
- }
- });
- } catch(err) {
- console.log("createAccount exception: " + JSON.stringify(err));
- }
createAccount(name: string, options?: CreateAccountOptions): Promise<void>
根據(jù)帳號(hào)名和可選項(xiàng)創(chuàng)建應(yīng)用帳號(hào)。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
options | 否 | 創(chuàng)建應(yīng)用帳號(hào)的選項(xiàng),可提供自定義數(shù)據(jù),但不建議包含敏感數(shù)據(jù)(如密碼、Token等)。不填無影響。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or options. |
12300004 | Account already exists. |
12300007 | The number of accounts reaches the upper limit. |
12400003 | The number of custom data reaches the upper limit. |
示例:
- let options = {
- customData: {
- "age": "10"
- }
- }
- try {
- appAccountManager.createAccount("LiSi", options).then(() => {
- console.log("createAccount successfully");
- }).catch((err) => {
- console.log("createAccount failed, error: " + JSON.stringify(err));
- });
- } catch(err) {
- console.log("createAccount exception: " + JSON.stringify(err));
- }
createAccountImplicitly(owner: string, callback: AuthCallback): void
根據(jù)指定的帳號(hào)所有者隱式地創(chuàng)建應(yīng)用帳號(hào)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
callback | 是 | 認(rèn)證器回調(diào)對(duì)象,返回創(chuàng)建結(jié)果。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid owner. |
12300007 | The number of accounts reaches the upper limit. |
12300010 | Account service busy. |
12300113 | Authenticator service not found. |
12300114 | Authenticator service exception. |
示例:
- function onResultCallback(code, result) {
- console.log("resultCode: " + code);
- console.log("result: " + JSON.stringify(result));
- }
- function onRequestRedirectedCallback(request) {
- let wantInfo = {
- deviceId: '',
- bundleName: 'com.example.accountjsdemo',
- action: 'ohos.want.action.viewData',
- entities: ['entity.system.default'],
- }
- this.context.startAbility(wantInfo).then(() => {
- console.log("startAbility successfully");
- }).catch((err) => {
- console.log("startAbility err: " + JSON.stringify(err));
- })
- }
- try {
- appAccountManager.createAccountImplicitly("com.example.accountjsdemo", {
- onResult: onResultCallback,
- onRequestRedirected: onRequestRedirectedCallback
- });
- } catch (err) {
- console.log("createAccountImplicitly exception: " + JSON.stringify(err));
- }
createAccountImplicitly(owner: string, options: CreateAccountImplicitlyOptions, callback: AuthCallback): void
根據(jù)指定的帳號(hào)所有者和可選項(xiàng)隱式地創(chuàng)建應(yīng)用帳號(hào)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
options | 是 | 隱式創(chuàng)建帳號(hào)的選項(xiàng)。 | |
callback | 是 | 認(rèn)證器回調(diào)對(duì)象,返回創(chuàng)建結(jié)果。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or options. |
12300007 | The number of accounts reaches the upper limit. |
12300010 | Account service busy. |
12300113 | Authenticator service not found. |
12300114 | Authenticator service exception. |
示例:
- function onResultCallback(code, result) {
- console.log("resultCode: " + code);
- console.log("result: " + JSON.stringify(result));
- }
- function onRequestRedirectedCallback(request) {
- let wantInfo = {
- deviceId: '',
- bundleName: 'com.example.accountjsdemo',
- action: 'ohos.want.action.viewData',
- entities: ['entity.system.default'],
- }
- this.context.startAbility(wantInfo).then(() => {
- console.log("startAbility successfully");
- }).catch((err) => {
- console.log("startAbility err: " + JSON.stringify(err));
- })
- }
- let options = {
- authType: "getSocialData",
- requiredLabels: [ "student" ]
- };
- try {
- appAccountManager.createAccountImplicitly("com.example.accountjsdemo", options, {
- onResult: onResultCallback,
- onRequestRedirected: onRequestRedirectedCallback
- });
- } catch (err) {
- console.log("createAccountImplicitly exception: " + JSON.stringify(err));
- }
removeAccount(name: string, callback: AsyncCallback<void>): void
刪除應(yīng)用帳號(hào)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)刪除成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name. |
12300003 | Account not found. |
示例:
- try {
- appAccountManager.removeAccount("ZhaoLiu", (err) => {
- if (err) {
- console.log("removeAccount failed, error: " + JSON.stringify(err));
- } else {
- console.log("removeAccount successfully");
- }
- });
- } catch(err) {
- console.log("removeAccount exception: " + JSON.stringify(err));
- }
removeAccount(name: string): Promise<void>
刪除應(yīng)用帳號(hào)。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name. |
12300003 | Account not found. |
示例:
- try {
- appAccountManager.removeAccount("Lisi").then(() => {
- console.log("removeAccount successfully");
- }).catch((err) => {
- console.log("removeAccount failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("removeAccount exception: " + JSON.stringify(err));
- }
setAppAccess(name: string, bundleName: string, isAccessible: boolean, callback: AsyncCallback<void>): void
設(shè)置指定應(yīng)用對(duì)特定帳號(hào)的訪問權(quán)限。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
bundleName | string | 是 | 第三方應(yīng)用的包名。 |
isAccessible | boolean | 是 | 是否可訪問。true表示允許訪問,false表示禁止訪問。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù),如果設(shè)置成功,err為null,否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or bundleName. |
12300003 | Account not found. |
12400001 | Application not found. |
示例:
- try {
- appAccountManager.setAppAccess("ZhangSan", "com.example.accountjsdemo", true, (err) => {
- if (err) {
- console.log("setAppAccess failed: " + JSON.stringify(err));
- } else {
- console.log("setAppAccess successfully");
- }
- });
- } catch (err) {
- console.log("setAppAccess exception: " + JSON.stringify(err));
- }
setAppAccess(name: string, bundleName: string, isAccessible: boolean): Promise<void>
設(shè)置指定應(yīng)用對(duì)特定帳號(hào)的數(shù)據(jù)訪問權(quán)限。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
bundleName | string | 是 | 第三方應(yīng)用的包名。 |
isAccessible | boolean | 是 | 是否可訪問。true表示允許訪問,false表示禁止訪問。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or bundleName. |
12300003 | Account not found. |
12400001 | Application not found. |
示例:
- try {
- appAccountManager.setAppAccess("ZhangSan", "com.example.accountjsdemo", true).then(() => {
- console.log("setAppAccess successfully");
- }).catch((err) => {
- console.log("setAppAccess failed: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("setAppAccess exception: " + JSON.stringify(err));
- }
checkAppAccess(name: string, bundleName: string, callback: AsyncCallback<boolean>): void
檢查指定應(yīng)用對(duì)特定帳號(hào)的數(shù)據(jù)是否可訪問。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
bundleName | string | 是 | 第三方應(yīng)用的包名。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。返回true表示指定應(yīng)用可訪問特定帳號(hào)的數(shù)據(jù);返回false表示不可訪問。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or bundleName. |
12300003 | Account not found. |
12400001 | Application not found. |
示例:
- try {
- appAccountManager.checkAppAccess("ZhangSan", "com.example.accountjsdemo", (err, isAccessible) => {
- if (err) {
- console.log("checkAppAccess failed, error: " + JSON.stringify(err));
- } else {
- console.log("checkAppAccess successfully");
- }
- });
- } catch (err) {
- console.log("checkAppAccess exception: " + JSON.stringify(err));
- }
checkAppAccess(name: string, bundleName: string): Promise<boolean>
檢查指定應(yīng)用對(duì)特定帳號(hào)的數(shù)據(jù)是否可訪問。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
bundleName | string | 是 | 第三方應(yīng)用的包名。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對(duì)象。返回true表示指定應(yīng)用可訪問特定帳號(hào)的數(shù)據(jù);返回false表示不可訪問。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or bundleName. |
12300003 | Account not found. |
12400001 | Application not found. |
示例:
- try {
- appAccountManager.checkAppAccess("ZhangSan", "com.example.accountjsdemo").then((isAccessible) => {
- console.log("checkAppAccess successfully, isAccessible: " + isAccessible);
- }).catch((err) => {
- console.log("checkAppAccess failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("checkAppAccess exception: " + JSON.stringify(err));
- }
setDataSyncEnabled(name: string, isEnabled: boolean, callback: AsyncCallback<void>): void
開啟或禁止指定應(yīng)用帳號(hào)的數(shù)據(jù)同步功能。使用callback異步回調(diào)。
需要權(quán)限: ohos.permission.DISTRIBUTED_DATASYNC
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
isEnabled | boolean | 是 | 是否開啟數(shù)據(jù)同步。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)開啟或禁止成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name. |
12300003 | Account not found. |
示例:
- try {
- appAccountManager.setDataSyncEnabled("ZhangSan", true, (err) => {
- console.log("setDataSyncEnabled err: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("setDataSyncEnabled err: " + JSON.stringify(err));
- }
setDataSyncEnabled(name: string, isEnabled: boolean): Promise<void>
開啟或禁止指定應(yīng)用帳號(hào)的數(shù)據(jù)同步功能。使用Promise異步回調(diào)。
需要權(quán)限: ohos.permission.DISTRIBUTED_DATASYNC
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
isEnabled | boolean | 是 | 是否開啟數(shù)據(jù)同步。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name. |
12300003 | Account not found. |
示例:
- try {
- appAccountManager .setDataSyncEnabled("ZhangSan", true).then(() => {
- console.log('setDataSyncEnabled Success');
- }).catch((err) => {
- console.log("setDataSyncEnabled err: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("setDataSyncEnabled err: " + JSON.stringify(err));
- }
checkDataSyncEnabled(name: string, callback: AsyncCallback<boolean>): void
檢查指定應(yīng)用帳號(hào)是否開啟數(shù)據(jù)同步功能。使用callback異步回調(diào)。
需要權(quán)限: ohos.permission.DISTRIBUTED_DATASYNC
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。返回true表示指定應(yīng)用帳號(hào)已開啟數(shù)據(jù)同步功能;返回false表示未開啟。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name. |
12300003 | Account not found. |
示例:
- try {
- appAccountManager.checkDataSyncEnabled("ZhangSan", (err, isEnabled) => {
- if (err) {
- console.log("checkDataSyncEnabled failed, err: " + JSON.stringify(err));
- } else {
- console.log('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled);
- }
- });
- } catch (err) {
- console.log("checkDataSyncEnabled err: " + JSON.stringify(err));
- }
checkDataSyncEnabled(name: string): Promise<boolean>
檢查指定應(yīng)用帳號(hào)是否開啟數(shù)據(jù)同步功能。使用Promise異步回調(diào)。
需要權(quán)限: ohos.permission.DISTRIBUTED_DATASYNC
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對(duì)象。返回true表示指定應(yīng)用帳號(hào)已開啟數(shù)據(jù)同步功能;返回false表示未開啟。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name. |
12300003 | Account not found. |
示例:
- try {
- appAccountManager.checkDataSyncEnabled("ZhangSan").then((isEnabled) => {
- console.log("checkDataSyncEnabled successfully, isEnabled: " + isEnabled);
- }).catch((err) => {
- console.log("checkDataSyncEnabled failed, err: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("checkDataSyncEnabled err: " + JSON.stringify(err));
- }
setCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void
設(shè)置指定應(yīng)用帳號(hào)的憑據(jù)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
credentialType | string | 是 | 憑據(jù)類型。 |
credential | string | 是 | 憑據(jù)取值。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)憑據(jù)設(shè)置成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or credentialType or credential. |
12300003 | Account not found. |
示例:
- try {
- appAccountManager.setCredential("ZhangSan", "PIN_SIX", "xxxxxx", (err) => {
- if (err) {
- console.log("setCredential failed, error: " + JSON.stringify(err));
- } else {
- console.log("setCredential successfully");
- }
- });
- } catch (err) {
- console.log("setCredential exception: " + JSON.stringify(err));
- }
setCredential(name: string, credentialType: string, credential: string): Promise<void>
設(shè)置指定應(yīng)用帳號(hào)的憑據(jù)。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
credentialType | string | 是 | 憑據(jù)類型。 |
credential | string | 是 | 憑據(jù)取值。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or credentialType or credential. |
12300003 | Account not found. |
示例:
- try {
- appAccountManager.setCredential("ZhangSan", "PIN_SIX", "xxxxxx").then(() => {
- console.log("setCredential successfully");
- }).catch((err) => {
- console.log("setCredential failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("setCredential exception: " + JSON.stringify(err));
- }
getCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void
獲取指定應(yīng)用帳號(hào)的憑據(jù)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
credentialType | string | 是 | 憑據(jù)類型。 |
callback | AsyncCallback<string> | 是 | 回調(diào)函數(shù)。當(dāng)獲取憑據(jù)成功時(shí),err為null,data為指定應(yīng)用帳號(hào)的憑據(jù);否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or credentialType. |
12300003 | Account not found. |
12300102 | Credential not found. |
示例:
- try {
- appAccountManager.getCredential("ZhangSan", "PIN_SIX", (err, result) => {
- if (err) {
- console.log("getCredential failed, error: " + JSON.stringify(err));
- } else {
- console.log('getCredential successfully, result: ' + result);
- }
- });
- } catch (err) {
- console.log("getCredential err: " + JSON.stringify(err));
- }
getCredential(name: string, credentialType: string): Promise<string>
獲取指定應(yīng)用帳號(hào)的憑據(jù)。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
credentialType | string | 是 | 憑據(jù)類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對(duì)象,返回指定應(yīng)用帳號(hào)的憑據(jù)。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or credentialType. |
12300003 | Account not found. |
12300102 | Credential not found. |
示例:
- try {
- appAccountManager.getCredential("ZhangSan", "PIN_SIX").then((credential) => {
- console.log("getCredential successfully, credential: " + credential);
- }).catch((err) => {
- console.log("getCredential failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("getCredential exception: " + JSON.stringify(err));
- }
setCustomData(name: string, key: string, value: string, callback: AsyncCallback<void>): void
設(shè)置指定應(yīng)用帳號(hào)的自定義數(shù)據(jù)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
key | string | 是 | 自定義數(shù)據(jù)的鍵名。 |
value | string | 是 | 自定義數(shù)據(jù)的取值。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)設(shè)置自定義數(shù)據(jù)成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or key or value. |
12300003 | Account not found. |
12400003 | The number of custom data reaches the upper limit. |
示例:
- try {
- appAccountManager.setCustomData("ZhangSan", "age", "12", (err) => {
- if (err) {
- console.log("setCustomData failed, error: " + JSON.stringify(err));
- } else {
- console.log("setCustomData successfully");
- }
- });
- } catch (err) {
- console.log("setCustomData exception: " + JSON.stringify(err));
- }
setCustomData(name: string, key: string, value: string): Promise<void>
設(shè)置指定應(yīng)用帳號(hào)的自定義數(shù)據(jù)。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
key | string | 是 | 自定義數(shù)據(jù)的鍵名。 |
value | string | 是 | 自定義數(shù)據(jù)的取值。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or key or value. |
12300003 | Account not found. |
12400003 | The number of custom data reaches the upper limit. |
示例:
- try {
- appAccountManager.setCustomData("ZhangSan", "age", "12").then(() => {
- console.log("setCustomData successfully");
- }).catch((err) => {
- console.log("setCustomData failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("setCustomData exception: " + JSON.stringify(err));
- }
getCustomData(name: string, key: string, callback: AsyncCallback<string>): void
根據(jù)指定鍵名獲取特定應(yīng)用帳號(hào)的自定義數(shù)據(jù)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
key | string | 是 | 自定義數(shù)據(jù)的鍵名。 |
callback | AsyncCallback<string> | 是 | 回調(diào)函數(shù)。當(dāng)獲取成功時(shí),err為null,data為自定義數(shù)據(jù)的取值;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or key. |
12300003 | Account not found. |
12400002 | Custom data not found. |
示例:
- try {
- appAccountManager.getCustomData("ZhangSan", "age", (err, data) => {
- if (err) {
- console.log('getCustomData failed, error: ' + err);
- } else {
- console.log("getCustomData successfully, data: " + data);
- }
- });
- } catch (err) {
- console.log("getCustomData exception: " + JSON.stringify(err));
- }
getCustomData(name: string, key: string): Promise<string>
根據(jù)指定鍵名獲取特定應(yīng)用帳號(hào)的自定義數(shù)據(jù)。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
key | string | 是 | 自定義數(shù)據(jù)的鍵名。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對(duì)象,返回自定義數(shù)據(jù)的取值。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or key. |
12300003 | Account not found. |
12400002 | Custom data not found. |
示例:
- try {
- appAccountManager.getCustomData("ZhangSan", "age").then((data) => {
- console.log("getCustomData successfully, data: " + data);
- }).catch((err) => {
- console.log("getCustomData failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("getCustomData exception: " + JSON.stringify(err));
- }
getCustomDataSync(name: string, key: string): string;
根據(jù)指定鍵名獲取特定應(yīng)用帳號(hào)的自定義數(shù)據(jù)。使用同步方式返回結(jié)果。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
key | string | 是 | 自定義數(shù)據(jù)的鍵名。 |
返回值:
類型 | 說明 |
---|---|
string | 自定義數(shù)據(jù)的取值。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or key. |
12300003 | Account not found. |
12400002 | Custom data not found. |
示例:
- try {
- let value = appAccountManager.getCustomDataSync("ZhangSan", "age");
- console.info("getCustomDataSync successfully, vaue:" + value);
- } catch (err) {
- console.error("getCustomDataSync failed, error: " + JSON.stringify(err));
- }
getAllAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void
獲取所有可訪問的應(yīng)用帳號(hào)信息。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<Array<AppAccountInfo>> | 是 | 回調(diào)函數(shù)。當(dāng)查詢成功時(shí),err為null,data為獲取到的應(yīng)用帳號(hào)信息列表;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
示例:
- try {
- appAccountManager.getAllAccounts((err, data) => {
- if (err) {
- console.debug("getAllAccounts failed, error:" + JSON.stringify(err));
- } else {
- console.debug("getAllAccounts successfully");
- }
- });
- } catch (err) {
- console.debug("getAllAccounts exception: " + JSON.stringify(err));
- }
getAllAccounts(): Promise<Array<AppAccountInfo>>
獲取所有可訪問的應(yīng)用帳號(hào)信息。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
返回值:
類型 | 說明 |
---|---|
Promise<Array<AppAccountInfo>> | Promise對(duì)象,返回全部應(yīng)用已授權(quán)帳號(hào)信息對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
示例:
- try {
- appAccountManager.getAllAccounts().then((data) => {
- console.debug("getAllAccounts successfully");
- }).catch((err) => {
- console.debug("getAllAccounts failed, error:" + JSON.stringify(err));
- });
- } catch (err) {
- console.debug("getAllAccounts exception: " + JSON.stringify(err));
- }
getAccountsByOwner(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void
根據(jù)應(yīng)用帳號(hào)所有者獲取調(diào)用方可訪問的應(yīng)用帳號(hào)列表。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
callback | AsyncCallback<Array<AppAccountInfo>> | 是 | 回調(diào)函數(shù)。如果獲取成功,err為null,data為獲取到的應(yīng)用帳號(hào)列表;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid owner. |
12400001 | Application not found. |
示例:
- try {
- appAccountManager.getAccountsByOwner("com.example.accountjsdemo2", (err, data) => {
- if (err) {
- console.debug("getAccountsByOwner failed, error:" + JSON.stringify(err));
- } else {
- console.debug("getAccountsByOwner successfully, data:" + JSON.stringify(data));
- }
- });
- } catch (err) {
- console.debug("getAccountsByOwner exception:" + JSON.stringify(err));
- }
getAccountsByOwner(owner: string): Promise<Array<AppAccountInfo>>
根據(jù)應(yīng)用帳號(hào)所有者獲取調(diào)用方可訪問的應(yīng)用帳號(hào)列表。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
返回值:
類型 | 說明 |
---|---|
Promise<Array<AppAccountInfo>> | Promise對(duì)象,返回獲取到的應(yīng)用帳號(hào)列表。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid owner. |
12400001 | Application not found. |
示例:
- try {
- appAccountManager.getAccountsByOwner("com.example.accountjsdemo2").then((data) => {
- console.debug("getAccountsByOwner successfully, data:" + JSON.stringify(data));
- }).catch((err) => {
- console.debug("getAccountsByOwner failed, error:" + JSON.stringify(err));
- });
- } catch (err) {
- console.debug("getAccountsByOwner exception:" + JSON.stringify(err));
- }
on(type: 'accountChange', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void
訂閱指定應(yīng)用的帳號(hào)信息變更事件。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | 'accountChange' | 是 | 事件回調(diào)類型,支持的事件為'accountChange',當(dāng)目標(biāo)應(yīng)用更新帳號(hào)信息時(shí),觸發(fā)該事件。 |
owners | Array<string> | 是 | 應(yīng)用帳號(hào)所有者的包名列表。 |
callback | Callback<Array<AppAccountInfo>> | 是 | 回調(diào)函數(shù),返回信息發(fā)生變更的應(yīng)用帳號(hào)列表。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid type or owners. |
12300011 | Callback has been registered. |
12400001 | Application not found. |
示例:
- function changeOnCallback(data){
- console.log("receive change data:" + JSON.stringify(data));
- }
- try{
- appAccountManager.on("accountChange", ["com.example.actsaccounttest"], changeOnCallback);
- } catch(err) {
- console.error("on accountChange failed, error:" + JSON.stringify(err));
- }
off(type: 'accountChange', callback?: Callback<Array<AppAccountInfo>>): void
取消訂閱帳號(hào)信息變更事件。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | 'accountChange' | 是 | 事件回調(diào)類型,支持的事件為'accountChange',當(dāng)帳號(hào)所有者更新帳號(hào)信息時(shí),觸發(fā)該事件。 |
callback | Callback<Array<AppAccountInfo>> | 否 | 回調(diào)函數(shù),返回信息發(fā)生變更的應(yīng)用帳號(hào)列表。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid type. |
12300012 | Callback has not been registered. |
示例:
- function changeOnCallback(data){
- console.log("receive change data:" + JSON.stringify(data));
- }
- try{
- appAccountManager.on("accountChange", ["com.example.actsaccounttest"], changeOnCallback);
- } catch(err) {
- console.error("on accountChange failed, error:" + JSON.stringify(err));
- }
- try{
- appAccountManager.off('accountChange', changeOnCallback);
- }
- catch(err){
- console.error("off accountChange failed, error:" + JSON.stringify(err));
- }
auth(name: string, owner: string, authType: string, callback: AuthCallback): void
對(duì)應(yīng)用帳號(hào)進(jìn)行鑒權(quán)以獲取授權(quán)令牌。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。 |
callback | 是 | 回調(diào)對(duì)象,返回鑒權(quán)結(jié)果。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or owner or authType. |
12300003 | Account not found. |
12300010 | Account service busy. |
12300113 | Authenticator service not found. |
12300114 | Authenticator service exception. |
示例:
- function onResultCallback(code, authResult) {
- console.log("resultCode: " + code);
- console.log("authResult: " + JSON.stringify(authResult));
- }
- function onRequestRedirectedCallback(request) {
- let wantInfo = {
- deviceId: '',
- bundleName: 'com.example.accountjsdemo',
- action: 'ohos.want.action.viewData',
- entities: ['entity.system.default'],
- }
- this.context.startAbility(wantInfo).then(() => {
- console.log("startAbility successfully");
- }).catch((err) => {
- console.log("startAbility err: " + JSON.stringify(err));
- })
- }
- try {
- appAccountManager.auth("LiSi", "com.example.accountjsdemo", "getSocialData", {
- onResult: onResultCallback,
- onRequestRedirected: onRequestRedirectedCallback
- });
- } catch (err) {
- console.log("auth exception: " + JSON.stringify(err));
- }
auth(name: string, owner: string, authType: string, options: {[key: string]: Object}, callback: AuthCallback): void
對(duì)應(yīng)用帳號(hào)進(jìn)行鑒權(quán)以獲取授權(quán)令牌。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。 |
options | {[key: string]: Object} | 是 | 鑒權(quán)所需的可選項(xiàng)。 |
callback | 是 | 回調(diào)對(duì)象,返回鑒權(quán)結(jié)果。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or owner or authType. |
12300003 | Account not exist. |
12300010 | Account service busy. |
12300113 | Authenticator service not found. |
12300114 | Authenticator service exception. |
示例:
- function onResultCallback(code, authResult) {
- console.log("resultCode: " + code);
- console.log("authResult: " + JSON.stringify(authResult));
- }
- function onRequestRedirectedCallback(request) {
- let wantInfo = {
- deviceId: '',
- bundleName: 'com.example.accountjsdemo',
- action: 'ohos.want.action.viewData',
- entities: ['entity.system.default'],
- }
- this.context.startAbility(wantInfo).then(() => {
- console.log("startAbility successfully");
- }).catch((err) => {
- console.log("startAbility err: " + JSON.stringify(err));
- })
- }
- let options = {
- "password": "xxxx",
- };
- try {
- appAccountManager.auth("LiSi", "com.example.accountjsdemo", "getSocialData", options, {
- onResult: onResultCallback,
- onRequestRedirected: onRequestRedirectedCallback
- });
- } catch (err) {
- console.log("auth exception: " + JSON.stringify(err));
- }
getAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void
獲取指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。 |
callback | AsyncCallback<string> | 是 | 回調(diào)函數(shù)。當(dāng)獲取成功時(shí),err為null,data為授權(quán)令牌值;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name, owner or authType. |
12300003 | Account not found. |
12300107 | AuthType not found. |
示例:
- try {
- appAccountManager.getAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", (err, token) => {
- if (err) {
- console.log("getAuthToken failed, error: " + JSON.stringify(err));
- } else {
- console.log("getAuthToken successfully, token: " + token);
- }
- });
- } catch (err) {
- console.log("getAuthToken exception: " + JSON.stringify(err));
- }
getAuthToken(name: string, owner: string, authType: string): Promise<string>
獲取指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對(duì)象,返回授權(quán)令牌。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or owner or authType. |
12300003 | Account not found. |
12300107 | AuthType not found. |
示例:
- try {
- appAccountManager.getAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData").then((token) => {
- console.log("getAuthToken successfully, token: " + token);
- }).catch((err) => {
- console.log("getAuthToken failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("getAuthToken exception: " + JSON.stringify(err));
- }
setAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void
為指定應(yīng)用帳號(hào)設(shè)置特定鑒權(quán)類型的授權(quán)令牌。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
token | string | 是 | 授權(quán)令牌。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)設(shè)置成功時(shí),err為null;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or authType or token. |
12300003 | Account not found. |
12400004 | The number of token reaches the upper limit. |
示例:
- try {
- appAccountManager.setAuthToken("LiSi", "getSocialData", "xxxx", (err) => {
- if (err) {
- console.log("setAuthToken failed, error: " + JSON.stringify(err));
- } else {
- console.log("setAuthToken successfully");
- }
- });
- } catch (err) {
- console.log('setAuthToken exception: ' + JSON.stringify(err));
- }
setAuthToken(name: string, authType: string, token: string): Promise<void>
為指定應(yīng)用帳號(hào)設(shè)置特定鑒權(quán)類型的授權(quán)令牌。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
token | string | 是 | 授權(quán)令牌。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or authType or token. |
12300003 | Account not found. |
12400004 | The number of token reaches the upper limit. |
示例:
- try {
- appAccountManager.setAuthToken("LiSi", "getSocialData", "xxxx").then(() => {
- console.log("setAuthToken successfully");
- }).catch((err) => {
- console.log("setAuthToken failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("setAuthToken exception: " + JSON.stringify(err));
- }
deleteAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void
刪除指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。 |
token | string | 是 | 授權(quán)令牌。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)刪除成功時(shí),err為null;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or owner or authType or token. |
12300003 | Account not found. |
12300107 | AuthType not found. |
示例:
- try {
- appAccountManager.deleteAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx", (err) => {
- if (err) {
- console.log('deleteAuthToken failed, error: ' + JSON.stringify(err));
- } else {
- console.log("deleteAuthToken successfully");
- }
- });
- } catch (err) {
- console.log('deleteAuthToken exception: ' + JSON.stringify(err));
- }
deleteAuthToken(name: string, owner: string, authType: string, token: string): Promise<void>
刪除指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。 |
token | string | 是 | 授權(quán)令牌。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or owner or authType or token. |
12300003 | Account not found. |
12300107 | AuthType not found. |
示例:
- try {
- appAccountManager.deleteAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx").then(() => {
- console.log("deleteAuthToken successfully");
- }).catch((err) => {
- console.log('deleteAuthToken failed, error: ' + JSON.stringify(err));
- });
- } catch (err) {
- console.log('deleteAuthToken exception: ' + JSON.stringify(err));
- }
setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void
設(shè)置指定帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌對(duì)指定應(yīng)用的可見性。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
bundleName | string | 是 | 被設(shè)置可見性的應(yīng)用包名。 |
isVisible | boolean | 是 | 是否可見。true表示可見,false表示不可見。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)設(shè)置成功時(shí),err為null;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or authType or bundleName. |
12300003 | Account not found. |
12300107 | AuthType not found. |
12400001 | Application not found. |
12400005 | The size of authorization list reaches the upper limit. |
示例:
- try {
- appAccountManager.setAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true, (err) => {
- if (err) {
- console.log("setAuthTokenVisibility failed, error: " + JSON.stringify(err));
- } else {
- console.log("setAuthTokenVisibility successfully");
- }
- });
- } catch (err) {
- console.log("setAuthTokenVisibility exception: " + JSON.stringify(err));
- }
setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void>
設(shè)置指定帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌對(duì)指定應(yīng)用的可見性。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
bundleName | string | 是 | 被設(shè)置可見性的應(yīng)用包名。 |
isVisible | boolean | 是 | 是否可見。true表示可見,false表示不可見。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or authType or bundleName. |
12300003 | Account not found. |
12300107 | AuthType not found. |
12400001 | Application not found. |
12400005 | The size of authorization list reaches the upper limit. |
示例:
- try {
- appAccountManager.setAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true).then(() => {
- console.log("setAuthTokenVisibility successfully");
- }).catch((err) => {
- console.log("setAuthTokenVisibility failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("setAuthTokenVisibility exception: " + JSON.stringify(err));
- }
checkAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void
檢查指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌對(duì)指定應(yīng)用的可見性。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
bundleName | string | 是 | 檢查可見性的應(yīng)用包名。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)檢查成功時(shí),err為null,data為true表示可見,data為false表示不可見;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or authType or bundleName. |
12300003 | Account not found. |
12300107 | AuthType not found. |
12400001 | Application not found. |
示例:
- try {
- appAccountManager.checkAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", (err, isVisible) => {
- if (err) {
- console.log("checkAuthTokenVisibility failed, error: " + JSON.stringify(err));
- } else {
- console.log("checkAuthTokenVisibility successfully, isVisible: " + isVisible);
- }
- });
- } catch (err) {
- console.log("checkAuthTokenVisibility exception: " + JSON.stringify(err));
- }
checkAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean>
檢查指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌對(duì)指定應(yīng)用的可見性。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
bundleName | string | 是 | 用于檢查可見性的應(yīng)用包名。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對(duì)象。返回true表示授權(quán)令牌對(duì)指定應(yīng)用的可見,返回false表示不可見。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or authType or bundleName. |
12300003 | Account not found. |
12300107 | AuthType not found. |
12400001 | Application not found. |
示例:
- try {
- appAccountManager.checkAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo").then((isVisible) => {
- console.log("checkAuthTokenVisibility successfully, isVisible: " + isVisible);
- }).catch((err) => {
- console.log("checkAuthTokenVisibility failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("checkAuthTokenVisibility exception: " + JSON.stringify(err));
- }
getAllAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<AuthTokenInfo>>): void
獲取指定帳號(hào)對(duì)調(diào)用方可見的所有授權(quán)令牌。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
callback | AsyncCallback<Array<AuthTokenInfo>> | 是 | 回調(diào)函數(shù)。當(dāng)獲取成功時(shí),err為null,data為授權(quán)令牌數(shù)組;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or owner. |
12300003 | Account not found. |
示例:
- try {
- appAccountManager.getAllAuthTokens("LiSi", "com.example.accountjsdemo", (err, tokenArr) => {
- if (err) {
- console.log("getAllAuthTokens failed, error: " + JSON.stringify(err));
- } else {
- console.log('getAllAuthTokens successfully, tokenArr: ' + tokenArr);
- }
- });
- } catch (err) {
- console.log("getAllAuthTokens exception: " + JSON.stringify(err));
- }
getAllAuthTokens(name: string, owner: string): Promise<Array<AuthTokenInfo>>
獲取指定帳號(hào)對(duì)調(diào)用方可見的所有授權(quán)令牌。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
返回值:
類型 | 說明 |
---|---|
Promise<Array<AuthTokenInfo>> | Promise對(duì)象,返回授權(quán)令牌數(shù)組。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or owner. |
12300003 | Account not found. |
示例:
- try {
- appAccountManager.getAllAuthTokens("LiSi", "com.example.accountjsdemo").then((tokenArr) => {
- console.log('getAllAuthTokens successfully, tokenArr: ' + JSON.stringify(tokenArr));
- }).catch((err) => {
- console.log("getAllAuthTokens failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("getAllAuthTokens exception: " + JSON.stringify(err));
- }
getAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void
獲取指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)列表,即被授權(quán)的包名數(shù)組(令牌的授權(quán)列表通過setAuthTokenVisibility來設(shè)置)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
callback | AsyncCallback<Array<string>> | 是 | 回調(diào)函數(shù)。當(dāng)獲取成功時(shí),err為null,data為被授權(quán)的包名數(shù)組;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or authType. |
12300003 | Account not found. |
12300107 | AuthType not found. |
示例:
- try {
- appAccountManager.getAuthList("com.example.accountjsdemo", "getSocialData", (err, authList) => {
- if (err) {
- console.log("getAuthList failed, error: " + JSON.stringify(err));
- } else {
- console.log("getAuthList successfully, authList: " + authList);
- }
- });
- } catch (err) {
- console.log('getAuthList exception: ' + JSON.stringify(err));
- }
getAuthList(name: string, authType: string): Promise<Array<string>>
獲取指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)列表,即被授權(quán)的包名數(shù)組(令牌的授權(quán)列表通過setAuthTokenVisibility來設(shè)置)。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<Array<string>> | Promise對(duì)象,返回被授權(quán)的包名數(shù)組。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or authType. |
12300003 | Account not found. |
12300107 | AuthType not found. |
示例:
- try {
- appAccountManager.getAuthList("com.example.accountjsdemo", "getSocialData").then((authList) => {
- console.log("getAuthList successfully, authList: " + authList);
- }).catch((err) => {
- console.log("getAuthList failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("getAuthList exception: " + JSON.stringify(err));
- }
getAuthCallback(sessionId: string, callback: AsyncCallback<AuthCallback>): void
獲取鑒權(quán)會(huì)話的認(rèn)證器回調(diào)對(duì)象。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
sessionId | string | 是 | 鑒權(quán)會(huì)話的標(biāo)識(shí)。 |
callback | AsyncCallback<AuthCallback> | 是 | 回調(diào)函數(shù)。當(dāng)獲取成功時(shí),err為null,data為鑒權(quán)會(huì)話的認(rèn)證器回調(diào)對(duì)象;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid sessionId. |
12300108 | Session not found. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- export default class EntryAbility extends UIAbility {
- onCreate(want, param) {
- var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
- try {
- appAccountManager.getAuthCallback(sessionId, (err, callback) => {
- if (err != null) {
- console.log("getAuthCallback err: " + JSON.stringify(err));
- return;
- }
- var result = {
- accountInfo: {
- name: "Lisi",
- owner: "com.example.accountjsdemo",
- },
- tokenInfo: {
- token: "xxxxxx",
- authType: "getSocialData"
- }
- };
- callback.onResult(0, result);
- });
- } catch (err) {
- console.log("getAuthCallback exception: " + JSON.stringify(err));
- }
- }
- }
getAuthCallback(sessionId: string): Promise<AuthCallback>
獲取鑒權(quán)會(huì)話的認(rèn)證器回調(diào)對(duì)象。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
sessionId | string | 是 | 鑒權(quán)會(huì)話的標(biāo)識(shí)。 |
返回值:
類型 | 說明 |
---|---|
Promise<AuthCallback> | Promise對(duì)象,返回鑒權(quán)會(huì)話的認(rèn)證器回調(diào)對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid sessionId. |
12300108 | Session not found. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- export default class EntryAbility extends UIAbility {
- onCreate(want, param) {
- var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
- try {
- appAccountManager.getAuthCallback(sessionId).then((callback) => {
- var result = {
- accountInfo: {
- name: "Lisi",
- owner: "com.example.accountjsdemo",
- },
- tokenInfo: {
- token: "xxxxxx",
- authType: "getSocialData"
- }
- };
- callback.onResult(0, result);
- }).catch((err) => {
- console.log("getAuthCallback err: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("getAuthCallback exception: " + JSON.stringify(err));
- }
- }
- }
queryAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void
獲取指定應(yīng)用的認(rèn)證器信息。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用包名。 |
callback | AsyncCallback<AuthenticatorInfo> | 是 | 回調(diào)函數(shù)。當(dāng)獲取成功時(shí),err為null,data為認(rèn)證器信息對(duì)象;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid owner. |
12300113 | Authenticator service not found. |
示例:
- try {
- appAccountManager.queryAuthenticatorInfo("com.example.accountjsdemo", (err, info) => {
- if (err) {
- console.log("queryAuthenticatorInfo failed, error: " + JSON.stringify(err));
- } else {
- console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info));
- }
- });
- } catch (err) {
- console.log("queryAuthenticatorInfo exception: " + JSON.stringify(err));
- }
queryAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo>
獲取指定應(yīng)用的認(rèn)證器信息。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用包名。 |
返回值:
類型 | 說明 |
---|---|
Promise<AuthenticatorInfo> | Promise對(duì)象,返回指定應(yīng)用的認(rèn)證器信息對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid owner. |
12300113 | Authenticator service not found. |
示例:
- try {
- appAccountManager.queryAuthenticatorInfo("com.example.accountjsdemo").then((info) => {
- console.log("queryAuthenticatorInfo successfully, info: " + JSON.stringify(info));
- }).catch((err) => {
- console.log("queryAuthenticatorInfo failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("queryAuthenticatorInfo exception: " + JSON.stringify(err));
- }
checkAccountLabels(name: string, owner: string, labels: Array<string>, callback: AsyncCallback<boolean>): void;
檢查指定應(yīng)用帳號(hào)是否滿足特定的標(biāo)簽集合。使用callback異步回調(diào)。該方法依賴目標(biāo)應(yīng)用的認(rèn)證器提供標(biāo)簽檢查的能力。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)的所有者。 |
labels | Array<string> | 是 | 標(biāo)簽數(shù)組。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)檢查成功時(shí),err為null,data為true表示滿足特定的標(biāo)簽集合,data為false表示不滿足;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or owner or labels. |
12300003 | Account not found. |
12300010 | Account service busy. |
12300113 | Authenticator service not found. |
12300114 | Authenticator service exception. |
示例:
- let labels = ["student"];
- try {
- appAccountManager.checkAccountLabels("zhangsan", "com.example.accountjsdemo", labels, (err, hasAllLabels) => {
- if (err) {
- console.log("checkAccountLabels failed, error: " + JSON.stringify(err));
- } else {
- console.log("checkAccountLabels successfully, hasAllLabels: " + hasAllLabels);
- }
- });
- } catch (err) {
- console.log("checkAccountLabels exception: " + JSON.stringify(err));
- }
checkAccountLabels(name: string, owner: string, labels: Array<string>): Promise<boolean>
檢查指定應(yīng)用帳號(hào)是否滿足特定的標(biāo)簽集合。使用Promise異步回調(diào)。該方法依賴目標(biāo)應(yīng)用的認(rèn)證器提供標(biāo)簽檢查的能力。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)的所有者。 |
labels | Array<string> | 是 | 標(biāo)簽數(shù)組。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對(duì)象。返回true表示指定帳號(hào)滿足特定的標(biāo)簽集合,返回false表示不滿足。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or owner or labels. |
12300003 | Account not found. |
12300010 | Account service busy. |
12300113 | Authenticator service not found. |
12300114 | Authenticator service exception. |
示例:
- let labels = ["student"];
- try {
- appAccountManager.checkAccountLabels("zhangsan", "com.example.accountjsdemo", labels).then((hasAllLabels) => {
- console.log('checkAccountLabels successfully: ' + hasAllLabels);
- }).catch((err) => {
- console.log("checkAccountLabels failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("checkAccountLabels exception: " + JSON.stringify(err));
- }
deleteCredential(name: string, credentialType: string, callback: AsyncCallback<void>): void
刪除指定應(yīng)用帳號(hào)的特定類型的憑據(jù)信息。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
credentialType | string | 是 | 憑據(jù)類型。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)刪除成功時(shí),err為null;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or credentialType. |
12300003 | Account not found. |
12300102 | Credential not found. |
示例:
- try {
- appAccountManager.deleteCredential("zhangsan", "PIN_SIX", (err) => {
- if (err) {
- console.log("deleteCredential failed, error: " + JSON.stringify(err));
- } else {
- console.log("deleteCredential successfully");
- }
- });
- } catch (err) {
- console.log("deleteCredential exception: " + JSON.stringify(err));
- }
deleteCredential(name: string, credentialType: string): Promise<void>
刪除指定應(yīng)用帳號(hào)的特定類型的憑據(jù)信息。使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
credentialType | string | 是 | 憑據(jù)類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or credentialType. |
12300003 | Account not found. |
12300102 | Credential not found. |
示例:
- try {
- appAccountManager.deleteCredential("zhangsan", "PIN_SIX").then(() => {
- console.log("deleteCredential successfully");
- }).catch((err) => {
- console.log("deleteCredential failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("deleteCredential exception: " + JSON.stringify(err));
- }
selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback<Array<AppAccountInfo>>): void
根據(jù)選項(xiàng)選擇調(diào)用方可訪問的帳號(hào)列表。使用callback異步回調(diào)。如果選項(xiàng)中包含標(biāo)簽約束,則該方法依賴目標(biāo)應(yīng)用的認(rèn)證器提供標(biāo)簽檢查的能力。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
options | SelectAccountsOptions | 是 | 選擇帳號(hào)的選項(xiàng)。 |
callback | AsyncCallback<Array<AppAccountInfo>> | 是 | 回調(diào)函數(shù)。當(dāng)根據(jù)選項(xiàng)選擇請(qǐng)求方可訪問的帳號(hào)列表時(shí),err為null,data為可訪問的帳號(hào)信息對(duì)象;否則為錯(cuò)誤對(duì)象。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid options. |
12300010 | Account service busy. |
12300114 | Authenticator service exception. |
示例:
- let options = {
- allowedOwners: [ "com.example.accountjsdemo" ],
- requiredLabels: [ "student" ]
- };
- try {
- appAccountManager.selectAccountsByOptions(options, (err, accountArr) => {
- if (err) {
- console.log("selectAccountsByOptions failed, error: " + JSON.stringify(err));
- } else {
- console.log("selectAccountsByOptions successfully, accountArr: " + JSON.stringify(accountArr));
- }
- });
- } catch (err) {
- console.log("selectAccountsByOptions exception: " + JSON.stringify(err));
- }
selectAccountsByOptions(options: SelectAccountsOptions): Promise<Array<AppAccountInfo>>
根據(jù)選項(xiàng)選擇調(diào)用方可訪問的帳號(hào)列表。使用Promise異步回調(diào)。如果選項(xiàng)中包含標(biāo)簽約束,則該方法依賴目標(biāo)應(yīng)用的認(rèn)證器提供標(biāo)簽檢查的能力。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
options | 是 | 選擇帳號(hào)的選項(xiàng)。 |
返回值:
類型 | 說明 |
---|---|
Promise<AppAccountInfo> | Promise對(duì)象,返回調(diào)用方可訪問的帳號(hào)列表。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid options. |
12300010 | Account service busy. |
12300114 | Authenticator service exception. |
示例:
- let options = {
- allowedOwners: ["com.example.accountjsdemo"]
- };
- try {
- appAccountManager.selectAccountsByOptions(options).then((accountArr) => {
- console.log("selectAccountsByOptions successfully, accountArr: " + JSON.stringify(accountArr));
- }).catch((err) => {
- console.log("selectAccountsByOptions failed, error: " + JSON.stringify(err));
- });
- } catch (err) {
- console.log("selectAccountsByOptions exception: " + JSON.stringify(err));
- }
verifyCredential(name: string, owner: string, callback: AuthCallback): void;
驗(yàn)證指定帳號(hào)的憑據(jù)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
callback | 是 | 回調(diào)函數(shù),返回驗(yàn)證結(jié)果。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or owner. |
12300003 | Account not found. |
12300010 | Account service busy. |
12300113 | Authenticator service not found. |
12300114 | Authenticator service exception. |
示例:
- try {
- appAccountManager.verifyCredential("zhangsan", "com.example.accountjsdemo", {
- onResult: (resultCode, result) => {
- console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode));
- console.log("verifyCredential onResult, result:" + JSON.stringify(result));
- },
- onRequestRedirected: (request) => {
- console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request));
- }
- });
- } catch (err) {
- console.log("verifyCredential err: " + JSON.stringify(err));
- }
verifyCredential(name: string, owner: string, options: VerifyCredentialOptions, callback: AuthCallback): void;
驗(yàn)證用戶憑據(jù)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
options | 是 | 驗(yàn)證憑據(jù)的選項(xiàng)。 | |
callback | 是 | 回調(diào)函數(shù),返回驗(yàn)證結(jié)果。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid name or owner or options. |
12300003 | Account not found. |
12300010 | Account service busy. |
12300113 | Authenticator service not found. |
12300114 | Authenticator service exception. |
示例:
- let options = {
- credentialType: "pin",
- credential: "123456"
- };
- try {
- appAccountManager.verifyCredential("zhangsan", "com.example.accountjsdemo", options, {
- onResult: (resultCode, result) => {
- console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode));
- console.log("verifyCredential onResult, result:" + JSON.stringify(result));
- },
- onRequestRedirected: (request) => {
- console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request));
- }
- });
- } catch (err) {
- console.log("verifyCredential err: " + JSON.stringify(err));
- }
setAuthenticatorProperties(owner: string, callback: AuthCallback): void;
設(shè)置指定應(yīng)用的認(rèn)證器屬性。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 認(rèn)證器的所有者。 |
callback | 是 | 回調(diào)函數(shù),返回設(shè)置屬性的結(jié)果。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid owner. |
12300010 | Account service busy. |
12300113 | Authenticator service not found. |
12300114 | Authenticator service exception. |
示例:
- try {
- appAccountManager.setAuthenticatorProperties("com.example.accountjsdemo", {
- onResult: (resultCode, result) => {
- console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode));
- console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result));
- },
- onRequestRedirected: (request) => {
- console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request));
- }
- });
- } catch (err) {
- console.log("setAuthenticatorProperties err: " + JSON.stringify(err));
- }
setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthCallback): void;
設(shè)置認(rèn)證器屬性。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 認(rèn)證器的所有者。 |
options | 是 | 設(shè)置屬性的選項(xiàng)。 | |
callback | 是 | 認(rèn)證器回調(diào),返回設(shè)置屬性的結(jié)果。 |
錯(cuò)誤碼:
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
12300001 | System service exception. |
12300002 | Invalid owner or options. |
12300010 | Account service busy. |
12300113 | Authenticator service not found. |
12300114 | Authenticator service exception. |
示例:
- let options = {
- properties: {"prop1": "value1"}
- };
- try {
- appAccountManager.setAuthenticatorProperties("com.example.accountjsdemo", options, {
- onResult: (resultCode, result) => {
- console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode));
- console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result));
- },
- onRequestRedirected: (request) => {
- console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request));
- }
- });
- } catch (err) {
- console.log("setAuthenticatorProperties err: " + JSON.stringify(err));
- }
addAccount(name: string, callback: AsyncCallback<void>): void
根據(jù)帳號(hào)名添加應(yīng)用帳號(hào)。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用createAccount替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)創(chuàng)建成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.addAccount("WangWu", (err) => {
- console.log("addAccount err: " + JSON.stringify(err));
- });
addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void
根據(jù)帳號(hào)名和額外信息添加應(yīng)用帳號(hào)。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用createAccount替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
extraInfo | string | 是 | 額外信息(能轉(zhuǎn)換string類型的其它信息),額外信息不能是應(yīng)用帳號(hào)的敏感信息(如應(yīng)用帳號(hào)密碼、token等)。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)創(chuàng)建成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.addAccount("LiSi", "token101", (err) => {
- console.log("addAccount err: " + JSON.stringify(err));
- });
addAccount(name: string, extraInfo?: string): Promise<void>
根據(jù)帳號(hào)名和額外信息添加應(yīng)用帳號(hào)。使用callback異步回調(diào)。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用createAccount替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
extraInfo | string | 否 | 額外信息(能轉(zhuǎn)換string類型的其它信息),額外信息不能是應(yīng)用帳號(hào)的敏感信息(如應(yīng)用帳號(hào)密碼、token等)。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
示例:
- appAccountManager.addAccount("LiSi", "token101").then(()=> {
- console.log('addAccount Success');
- }).catch((err) => {
- console.log("addAccount err: " + JSON.stringify(err));
- });
addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
根據(jù)指定的帳號(hào)所有者隱式地添加應(yīng)用帳號(hào)。使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用createAccountImplicitly替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。鑒權(quán)類型為自定義。 |
options | {[key: string]: any} | 是 | 鑒權(quán)所需要的可選項(xiàng)。可選項(xiàng)可根據(jù)自己需要設(shè)置。 |
callback | 是 | 認(rèn)證器回調(diào)對(duì)象,返回添加結(jié)果。 |
示例:
- function onResultCallback(code, result) {
- console.log("resultCode: " + code);
- console.log("result: " + JSON.stringify(result));
- }
- function onRequestRedirectedCallback(request) {
- let wantInfo = {
- deviceId: '',
- bundleName: 'com.example.accountjsdemo',
- action: 'ohos.want.action.viewData',
- entities: ['entity.system.default'],
- }
- this.context.startAbility(wantInfo).then(() => {
- console.log("startAbility successfully");
- }).catch((err) => {
- console.log("startAbility err: " + JSON.stringify(err));
- })
- }
- appAccountManager.addAccountImplicitly("com.example.accountjsdemo", "getSocialData", {}, {
- onResult: onResultCallback,
- onRequestRedirected: onRequestRedirectedCallback
- });
deleteAccount(name: string, callback: AsyncCallback<void>): void
刪除應(yīng)用帳號(hào)。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用removeAccount替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)刪除成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.deleteAccount("ZhaoLiu", (err) => {
- console.log("deleteAccount err: " + JSON.stringify(err));
- });
deleteAccount(name: string): Promise<void>
刪除應(yīng)用帳號(hào)。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用removeAccount替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
示例:
- appAccountManager.deleteAccount("ZhaoLiu").then(() => {
- console.log('deleteAccount Success');
- }).catch((err) => {
- console.log("deleteAccount err: " + JSON.stringify(err));
- });
disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void
禁止指定第三方應(yīng)用帳號(hào)名稱對(duì)指定的第三方應(yīng)用進(jìn)行訪問。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用setAppAccess替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
bundleName | string | 是 | 第三方應(yīng)用的包名。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)禁止指定第三方應(yīng)用帳號(hào)名稱對(duì)指定包名稱的第三方應(yīng)用進(jìn)行訪問設(shè)置成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.disableAppAccess("ZhangSan", "com.example.accountjsdemo", (err) => {
- console.log("disableAppAccess err: " + JSON.stringify(err));
- });
disableAppAccess(name: string, bundleName: string): Promise<void>
禁止指定第三方應(yīng)用帳號(hào)名稱對(duì)指定包名稱的第三方應(yīng)用進(jìn)行訪問。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用setAppAccess替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 要禁用訪問的第三方應(yīng)用帳號(hào)的名稱。 |
bundleName | string | 是 | 第三方應(yīng)用的包名。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
示例:
- appAccountManager.disableAppAccess("ZhangSan", "com.example.accountjsdemo").then(() => {
- console.log('disableAppAccess Success');
- }).catch((err) => {
- console.log("disableAppAccess err: " + JSON.stringify(err));
- });
enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void
允許指定第三方應(yīng)用帳號(hào)名稱對(duì)指定包名稱的第三方應(yīng)用進(jìn)行訪問。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用setAppAccess替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
bundleName | string | 是 | 第三方應(yīng)用的包名。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)允許指定第三方應(yīng)用帳號(hào)名稱對(duì)指定包名稱的第三方應(yīng)用進(jìn)行訪問設(shè)置成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.enableAppAccess("ZhangSan", "com.example.accountjsdemo", (err) => {
- console.log("enableAppAccess: " + JSON.stringify(err));
- });
enableAppAccess(name: string, bundleName: string): Promise<void>
允許指定第三方應(yīng)用帳號(hào)的名稱對(duì)指定包名稱的第三方應(yīng)用進(jìn)行訪問。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用setAppAccess替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
bundleName | string | 是 | 第三方應(yīng)用的包名。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
示例:
- appAccountManager.enableAppAccess("ZhangSan", "com.example.accountjsdemo").then(() => {
- console.log('enableAppAccess Success');
- }).catch((err) => {
- console.log("enableAppAccess err: " + JSON.stringify(err));
- });
checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void
檢查指定應(yīng)用帳號(hào)是否開啟數(shù)據(jù)同步功能。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用checkDataSyncEnabled替代。
需要權(quán)限: ohos.permission.DISTRIBUTED_DATASYNC
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。返回true表示指定應(yīng)用帳號(hào)已開啟數(shù)據(jù)同步功能;返回false表示未開啟。 |
示例:
- appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => {
- console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err));
- console.log('checkAppAccountSyncEnable result: ' + result);
- });
checkAppAccountSyncEnable(name: string): Promise<boolean>
檢查指定應(yīng)用帳號(hào)是否開啟數(shù)據(jù)同步功能。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用checkDataSyncEnabled替代。
需要權(quán)限: ohos.permission.DISTRIBUTED_DATASYNC
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對(duì)象。返回true表示指定應(yīng)用帳號(hào)已開啟數(shù)據(jù)同步功能;返回false表示未開啟。 |
示例:
- appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => {
- console.log('checkAppAccountSyncEnable, result: ' + data);
- }).catch((err) => {
- console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err));
- });
setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void
設(shè)置指定應(yīng)用帳號(hào)的憑據(jù)。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,建議使用setCredential替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
credentialType | string | 是 | 憑據(jù)類型。 |
credential | string | 是 | 憑據(jù)取值。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)設(shè)置此應(yīng)用程序帳號(hào)的憑據(jù)成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => {
- console.log("setAccountCredential err: " + JSON.stringify(err));
- });
setAccountCredential(name: string, credentialType: string, credential: string): Promise<void>
設(shè)置指定應(yīng)用帳號(hào)的憑據(jù)。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,建議使用setCredential替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
credentialType | string | 是 | 憑據(jù)類型。 |
credential | string | 是 | 憑據(jù)取值。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
示例:
- appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => {
- console.log('setAccountCredential Success');
- }).catch((err) => {
- console.log("setAccountCredential err: " + JSON.stringify(err));
- });
setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void
設(shè)置指定應(yīng)用帳號(hào)的額外信息。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用setCustomData替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
extraInfo | string | 是 | 額外信息(能轉(zhuǎn)換string類型的其它信息),額外信息不能是應(yīng)用帳號(hào)的敏感信息(如應(yīng)用帳號(hào)密碼、token等)。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)設(shè)置成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => {
- console.log("setAccountExtraInfo err: " + JSON.stringify(err));
- });
setAccountExtraInfo(name: string, extraInfo: string): Promise<void>
設(shè)置此應(yīng)用程序帳號(hào)的額外信息。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用setCustomData替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
extraInfo | string | 是 | 額外信息(能轉(zhuǎn)換string類型的其它信息),額外信息不能是應(yīng)用帳號(hào)的敏感信息(如應(yīng)用帳號(hào)密碼、token等)。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
示例:
- appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => {
- console.log('setAccountExtraInfo Success');
- }).catch((err) => {
- console.log("setAccountExtraInfo err: " + JSON.stringify(err));
- });
setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void
開啟或禁止指定應(yīng)用帳號(hào)的數(shù)據(jù)同步功能。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用setDataSyncEnabled替代。
需要權(quán)限: ohos.permission.DISTRIBUTED_DATASYNC
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
isEnable | boolean | 是 | 是否開啟數(shù)據(jù)同步。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)開啟或禁止成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => {
- console.log("setAppAccountSyncEnable err: " + JSON.stringify(err));
- });
setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void>
開啟或禁止指定應(yīng)用帳號(hào)的數(shù)據(jù)同步功能。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用setDataSyncEnabled替代。
需要權(quán)限: ohos.permission.DISTRIBUTED_DATASYNC
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
isEnable | boolean | 是 | 是否開啟數(shù)據(jù)同步。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
示例:
- appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => {
- console.log('setAppAccountSyncEnable Success');
- }).catch((err) => {
- console.log("setAppAccountSyncEnable err: " + JSON.stringify(err));
- });
setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void
設(shè)置指定應(yīng)用帳號(hào)的關(guān)聯(lián)數(shù)據(jù)。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用setCustomData替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
key | string | 是 | 關(guān)聯(lián)數(shù)據(jù)的鍵名。 |
value | string | 是 | 關(guān)聯(lián)數(shù)據(jù)的取值。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)設(shè)置與此應(yīng)用帳號(hào)關(guān)聯(lián)的數(shù)據(jù)成功時(shí),err為null,否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.setAssociatedData("ZhangSan", "k001", "v001", (err) => {
- console.log("setAssociatedData err: " + JSON.stringify(err));
- });
setAssociatedData(name: string, key: string, value: string): Promise<void>
設(shè)置指定應(yīng)用帳號(hào)的關(guān)聯(lián)數(shù)據(jù)。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用setCustomData替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
key | string | 是 | 關(guān)聯(lián)數(shù)據(jù)的鍵名。 |
value | string | 是 | 關(guān)聯(lián)數(shù)據(jù)的取值。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
示例:
- appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => {
- console.log('setAssociatedData Success');
- }).catch((err) => {
- console.log("setAssociatedData err: " + JSON.stringify(err));
- });
getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void
獲取所有可訪問的應(yīng)用帳號(hào)信息。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用getAllAccounts替代。
需要權(quán)限: ohos.permission.GET_ALL_APP_ACCOUNTS。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<Array<AppAccountInfo>> | 是 | 回調(diào)函數(shù)。當(dāng)查詢成功時(shí),err為null,data為獲取到的應(yīng)用帳號(hào)信息列表;否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.getAllAccessibleAccounts((err, data)=>{
- console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err));
- console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data));
- });
getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>>
獲取所有可訪問的應(yīng)用帳號(hào)信息。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用getAllAccounts替代。
需要權(quán)限: ohos.permission.GET_ALL_APP_ACCOUNTS。
系統(tǒng)能力: SystemCapability.Account.AppAccount
返回值:
類型 | 說明 |
---|---|
Promise<Array<AppAccountInfo>> | Promise對(duì)象,返回全部應(yīng)用已授權(quán)帳號(hào)信息對(duì)象。 |
示例:
- appAccountManager.getAllAccessibleAccounts().then((data) => {
- console.log('getAllAccessibleAccounts: ' + data);
- }).catch((err) => {
- console.log("getAllAccessibleAccounts err: " + JSON.stringify(err));
- });
getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void
根據(jù)應(yīng)用帳號(hào)所有者獲取調(diào)用方可訪問的應(yīng)用帳號(hào)列表。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用getAccountsByOwner替代。
需要權(quán)限: ohos.permission.GET_ALL_APP_ACCOUNTS。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
callback | AsyncCallback<Array<AppAccountInfo>> | 是 | 應(yīng)用帳號(hào)信息列表。 |
示例:
- const selfBundle = "com.example.actsgetallaaccounts";
- appAccountManager.getAllAccounts(selfBundle, (err, data)=>{
- console.debug("getAllAccounts err:" + JSON.stringify(err));
- console.debug("getAllAccounts data:" + JSON.stringify(data));
- });
getAllAccounts(owner: string): Promise<Array<AppAccountInfo>>
根據(jù)應(yīng)用帳號(hào)所有者獲取調(diào)用方可訪問的應(yīng)用帳號(hào)列表。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用getAccountsByOwner替代。
需要權(quán)限: ohos.permission.GET_ALL_APP_ACCOUNTS,僅系統(tǒng)應(yīng)用可用。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用包名稱。 |
返回值:
類型 | 說明 |
---|---|
Promise<Array<AppAccountInfo>> | Promise對(duì)象,返回指定應(yīng)用全部帳號(hào)信息對(duì)象。 |
示例:
- const selfBundle = "com.example.actsgetallaaccounts";
- appAccountManager.getAllAccounts(selfBundle).then((data) => {
- console.log('getAllAccounts: ' + data);
- }).catch((err) => {
- console.log("getAllAccounts err: " + JSON.stringify(err));
- });
getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void
獲取指定應(yīng)用帳號(hào)的憑據(jù)。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用getCredential替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
credentialType | string | 是 | 憑據(jù)類型。 |
callback | AsyncCallback<string> | 是 | 回調(diào)函數(shù)。當(dāng)獲取憑據(jù)成功時(shí),err為null,data為指定應(yīng)用帳號(hào)的憑據(jù);否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => {
- console.log("getAccountCredential err: " + JSON.stringify(err));
- console.log('getAccountCredential result: ' + result);
- });
getAccountCredential(name: string, credentialType: string): Promise<string>
獲取指定應(yīng)用帳號(hào)的憑據(jù)。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用getCredential替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
credentialType | string | 是 | 憑據(jù)類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對(duì)象,返回指定應(yīng)用帳號(hào)的憑據(jù)。 |
示例:
- appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => {
- console.log('getAccountCredential, result: ' + data);
- }).catch((err) => {
- console.log("getAccountCredential err: " + JSON.stringify(err));
- });
getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void
獲取指定應(yīng)用帳號(hào)的額外信息(能轉(zhuǎn)換成string類型的其它信息)。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用getCustomData替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
callback | AsyncCallback<string> | 是 | 回調(diào)函數(shù)。當(dāng)獲取此應(yīng)用帳號(hào)的額外信息成功時(shí),err為null,data返回此應(yīng)用帳號(hào)的額外信息對(duì)象;否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => {
- console.log("getAccountExtraInfo err: " + JSON.stringify(err));
- console.log('getAccountExtraInfo result: ' + result);
- });
getAccountExtraInfo(name: string): Promise<string>
獲取指定應(yīng)用帳號(hào)的額外信息(能轉(zhuǎn)換成string類型的其它信息)。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用getCustomData替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對(duì)象,返回此應(yīng)用程序帳號(hào)的額外信息對(duì)象。 |
示例:
- appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => {
- console.log('getAccountExtraInfo, result: ' + data);
- }).catch((err) => {
- console.log("getAccountExtraInfo err: " + JSON.stringify(err));
- });
getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void
根據(jù)指定鍵名獲取特定應(yīng)用帳號(hào)的關(guān)聯(lián)數(shù)據(jù)。使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用getCustomData替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
key | string | 是 | 關(guān)聯(lián)數(shù)據(jù)的鍵名。 |
callback | AsyncCallback<string> | 是 | 回調(diào)函數(shù)。當(dāng)獲取成功時(shí),err為null,data為關(guān)聯(lián)數(shù)據(jù)的取值;否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => {
- console.log("getAssociatedData err: " + JSON.stringify(err));
- console.log('getAssociatedData result: ' + result);
- });
getAssociatedData(name: string, key: string): Promise<string>
獲取與此應(yīng)用程序帳號(hào)關(guān)聯(lián)的數(shù)據(jù)。使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。建議使用getCustomData替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
key | string | 是 | 關(guān)聯(lián)數(shù)據(jù)的鍵名。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對(duì)象,返回關(guān)聯(lián)數(shù)據(jù)的取值。 |
示例:
- appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => {
- console.log('getAssociatedData: ' + data);
- }).catch((err) => {
- console.log("getAssociatedData err: " + JSON.stringify(err));
- });
on(type: 'change', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void
訂閱指定應(yīng)用的帳號(hào)信息變更事件。
從 API version 7開始支持,從API version 9開始廢棄。建議使用on('accountChange')替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | 'change' | 是 | 事件回調(diào)類型,支持的事件為'change',當(dāng)帳號(hào)所有者更新帳號(hào)信息時(shí),觸發(fā)該事件。 |
owners | Array<string> | 是 | 應(yīng)用帳號(hào)所有者的包名列表。 |
callback | Callback<Array<AppAccountInfo>> | 是 | 回調(diào)函數(shù),返回信息發(fā)生變更的應(yīng)用帳號(hào)列表。 |
示例:
- function changeOnCallback(data){
- console.debug("receive change data:" + JSON.stringify(data));
- }
- try{
- appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
- }
- catch(err){
- console.error("on accountOnOffDemo err:" + JSON.stringify(err));
- }
off(type: 'change', callback?: Callback<Array<AppAccountInfo>>): void
取消訂閱帳號(hào)信息變更事件。
從 API version 7開始支持,從API version 9開始廢棄。建議使用off('accountChange')替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | 'change' | 是 | 事件回調(diào)類型,支持的事件為'change',當(dāng)帳號(hào)所有者更新帳號(hào)信息時(shí),觸發(fā)該事件。 |
callback | Callback<Array<AppAccountInfo>> | 否 | 回調(diào)函數(shù),返回信息發(fā)生變更的應(yīng)用帳號(hào)列表。 |
示例:
- function changeOnCallback(data){
- console.debug("receive change data:" + JSON.stringify(data));
- appAccountManager.off('change', function(){
- console.debug("off finish");
- })
- }
- try{
- appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
- }
- catch(err){
- console.error("on accountOnOffDemo err:" + JSON.stringify(err));
- }
authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
對(duì)應(yīng)用帳號(hào)進(jìn)行鑒權(quán)以獲取授權(quán)令牌。使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用auth替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。 |
options | {[key: string]: any} | 是 | 鑒權(quán)所需的可選項(xiàng)。 |
callback | 是 | 回調(diào)對(duì)象,返回鑒權(quán)結(jié)果。 |
示例:
- function onResultCallback(code, result) {
- console.log("resultCode: " + code);
- console.log("result: " + JSON.stringify(result));
- }
- function onRequestRedirectedCallback(request) {
- let wantInfo = {
- deviceId: '',
- bundleName: 'com.example.accountjsdemo',
- action: 'ohos.want.action.viewData',
- entities: ['entity.system.default'],
- }
- this.context.startAbility(wantInfo).then(() => {
- console.log("startAbility successfully");
- }).catch((err) => {
- console.log("startAbility err: " + JSON.stringify(err));
- })
- }
- appAccountManager.authenticate("LiSi", "com.example.accountjsdemo", "getSocialData", {}, {
- onResult: onResultCallback,
- onRequestRedirected: onRequestRedirectedCallback
- });
getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void
獲取指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌。使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用getAuthToken替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。 |
callback | AsyncCallback<string> | 是 | 回調(diào)函數(shù)。當(dāng)獲取成功時(shí),err為null,data為授權(quán)令牌值;否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.getOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", (err, data) => {
- console.log('getOAuthToken err: ' + JSON.stringify(err));
- console.log('getOAuthToken token: ' + data);
- });
getOAuthToken(name: string, owner: string, authType: string): Promise<string>
獲取指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌。使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用getAuthToken替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對(duì)象,返回授權(quán)令牌。 |
示例:
- appAccountManager.getOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData").then((data) => {
- console.log('getOAuthToken token: ' + data);
- }).catch((err) => {
- console.log("getOAuthToken err: " + JSON.stringify(err));
- });
setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void
為指定應(yīng)用帳號(hào)設(shè)置特定鑒權(quán)類型的授權(quán)令牌。使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用setAuthToken替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
token | string | 是 | 授權(quán)令牌。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)設(shè)置成功時(shí),err為null;否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx", (err) => {
- console.log('setOAuthToken err: ' + JSON.stringify(err));
- });
setOAuthToken(name: string, authType: string, token: string): Promise<void>
為指定應(yīng)用帳號(hào)設(shè)置特定鑒權(quán)類型的授權(quán)令牌。使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用setAuthToken替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
token | string | 是 | 授權(quán)令牌。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
示例:
- appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx").then(() => {
- console.log('setOAuthToken successfully');
- }).catch((err) => {
- console.log('setOAuthToken err: ' + JSON.stringify(err));
- });
deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void
刪除指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌。使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用deleteAuthToken替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。 |
token | string | 是 | 授權(quán)令牌。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)刪除成功時(shí),err為null;否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx", (err) => {
- console.log('deleteOAuthToken err: ' + JSON.stringify(err));
- });
deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise<void>
刪除指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌。使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用deleteAuthToken替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
authType | string | 是 | 鑒權(quán)類型。 |
token | string | 是 | 授權(quán)令牌。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
示例:
- appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx").then(() => {
- console.log('deleteOAuthToken successfully');
- }).catch((err) => {
- console.log("deleteOAuthToken err: " + JSON.stringify(err));
- });
setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void
設(shè)置指定帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌對(duì)指定應(yīng)用的可見性。使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用setAuthTokenVisibility替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
bundleName | string | 是 | 被設(shè)置可見性的應(yīng)用包名。 |
isVisible | boolean | 是 | 是否可見。true表示可見,false表示不可見。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)設(shè)置成功時(shí),err為null;否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true, (err) => {
- console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
- });
setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void>
設(shè)置指定帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌對(duì)指定應(yīng)用的可見性。使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用setAuthTokenVisibility替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
bundleName | string | 是 | 被設(shè)置可見性的應(yīng)用包名。 |
isVisible | boolean | 是 | 是否可見。true表示可見,false表示不可見。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對(duì)象。 |
示例:
- appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true).then(() => {
- console.log('setOAuthTokenVisibility successfully');
- }).catch((err) => {
- console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
- });
checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void
檢查指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌對(duì)指定應(yīng)用的可見性。使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用checkAuthTokenVisibility替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
bundleName | string | 是 | 檢查可見性的應(yīng)用包名。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)檢查成功時(shí),err為null,data為true表示可見,data為false表示不可見;否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", (err, data) => {
- console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
- console.log('checkOAuthTokenVisibility isVisible: ' + data);
- });
checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean>
檢查指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)令牌對(duì)指定應(yīng)用的可見性。使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用checkAuthTokenVisibility替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
bundleName | string | 是 | 用于檢查可見性的應(yīng)用包名。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對(duì)象。返回true表示指定鑒權(quán)類型的OAuth令牌對(duì)特定應(yīng)用的可見,返回false表示不可見。 |
示例:
- appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo").then((data) => {
- console.log('checkOAuthTokenVisibility isVisible: ' + data);
- }).catch((err) => {
- console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
- });
getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void
獲取指定帳號(hào)對(duì)調(diào)用方可見的所有授權(quán)令牌。使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用getAllAuthTokens替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
callback | AsyncCallback<Array<OAuthTokenInfo>> | 是 | 回調(diào)函數(shù)。當(dāng)獲取成功時(shí),err為null,data為授權(quán)令牌數(shù)組;否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.getAllOAuthTokens("LiSi", "com.example.accountjsdemo", (err, data) => {
- console.log("getAllOAuthTokens err: " + JSON.stringify(err));
- console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
- });
getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenInfo>>
獲取指定帳號(hào)對(duì)調(diào)用方可見的所有授權(quán)令牌。使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用getAllAuthTokens替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
返回值:
類型 | 說明 |
---|---|
Promise<Array< OAuthTokenInfo>> | Promise對(duì)象,返回授權(quán)令牌數(shù)組。 |
示例:
- appAccountManager.getAllOAuthTokens("LiSi", "com.example.accountjsdemo").then((data) => {
- console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
- }).catch((err) => {
- console.log("getAllOAuthTokens err: " + JSON.stringify(err));
- });
getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void
獲取指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)列表,即被授權(quán)的包名數(shù)組(令牌的授權(quán)列表通過setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated)來設(shè)置)。使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用getAuthList替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
callback | AsyncCallback<Array<string>> | 是 | 回調(diào)函數(shù)。當(dāng)獲取成功時(shí),err為null,data為被授權(quán)的包名數(shù)組;否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.getOAuthList("com.example.accountjsdemo", "getSocialData", (err, data) => {
- console.log('getOAuthList err: ' + JSON.stringify(err));
- console.log('getOAuthList data: ' + JSON.stringify(data));
- });
getOAuthList(name: string, authType: string): Promise<Array<string>>
獲取指定應(yīng)用帳號(hào)的特定鑒權(quán)類型的授權(quán)列表,即被授權(quán)的包名數(shù)組(令牌的授權(quán)列表通過setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated)來設(shè)置)。使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用getAuthList替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 鑒權(quán)類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<Array<string>> | Promise對(duì)象,返回被授權(quán)的包名數(shù)組。 |
示例:
- appAccountManager.getOAuthList("com.example.accountjsdemo", "getSocialData").then((data) => {
- console.log('getOAuthList data: ' + JSON.stringify(data));
- }).catch((err) => {
- console.log("getOAuthList err: " + JSON.stringify(err));
- });
getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<AuthenticatorCallback>): void
獲取鑒權(quán)會(huì)話的認(rèn)證器回調(diào)。使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用getAuthCallback替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
sessionId | string | 是 | 鑒權(quán)會(huì)話的標(biāo)識(shí)。 |
callback | AsyncCallback<AuthenticatorCallback> | 是 | 回調(diào)函數(shù)。當(dāng)獲取鑒權(quán)會(huì)話的認(rèn)證器回調(diào)函數(shù)成功時(shí),err為null,data為認(rèn)證器回調(diào)函數(shù);否則為錯(cuò)誤對(duì)象。 |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- export default class EntryAbility extends UIAbility {
- onCreate(want, param) {
- var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
- appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => {
- if (err.code != account_appAccount.ResultCode.SUCCESS) {
- console.log("getAuthenticatorCallback err: " + JSON.stringify(err));
- return;
- }
- var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
- [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo",
- [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
- [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
- callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
- });
- }
- }
getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback>
獲取鑒權(quán)會(huì)話的認(rèn)證器回調(diào)。使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用getAuthCallback替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
sessionId | string | 是 | 鑒權(quán)會(huì)話的標(biāo)識(shí)。 |
返回值:
類型 | 說明 |
---|---|
Promise<AuthenticatorCallback> | Promise對(duì)象,返回鑒權(quán)會(huì)話的認(rèn)證器回調(diào)對(duì)象。 |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- export default class EntryAbility extends UIAbility {
- onCreate(want, param) {
- var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
- appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
- var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
- [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo",
- [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
- [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
- callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
- }).catch((err) => {
- console.log("getAuthenticatorCallback err: " + JSON.stringify(err));
- });
- }
- }
getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void
獲取指定應(yīng)用的認(rèn)證器信息。使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用queryAuthenticatorInfo替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
callback | AsyncCallback<AuthenticatorInfo> | 是 | 回調(diào)函數(shù)。當(dāng)獲取成功時(shí),err為null,data為認(rèn)證器信息對(duì)象;否則為錯(cuò)誤對(duì)象。 |
示例:
- appAccountManager.getAuthenticatorInfo("com.example.accountjsdemo", (err, data) => {
- console.log("getAuthenticatorInfo err: " + JSON.stringify(err));
- console.log('getAuthenticatorInfo data: ' + JSON.stringify(data));
- });
getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo>
獲取指定應(yīng)用的認(rèn)證器信息。使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄。建議使用queryAuthenticatorInfo替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
返回值:
類型 | 說明 |
---|---|
Promise<AuthenticatorInfo> | Promise對(duì)象,返回指定應(yīng)用的認(rèn)證器信息對(duì)象。 |
示例:
- appAccountManager.getAuthenticatorInfo("com.example.accountjsdemo").then((data) => {
- console.log('getAuthenticatorInfo: ' + JSON.stringify(data));
- }).catch((err) => {
- console.log("getAuthenticatorInfo err: " + JSON.stringify(err));
- });
表示應(yīng)用帳號(hào)信息。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 應(yīng)用帳號(hào)所有者的包名。 |
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
表示Auth令牌信息。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
authType9+ | string | 是 | 令牌的鑒權(quán)類型。 |
token9+ | string | 是 | 令牌的取值。 |
account9+ | 否 | 令牌所屬的帳號(hào)信息。 |
表示OAuth令牌信息。
從 API version 8開始支持,從API version 9開始廢棄。建議使用AuthTokenInfo替代。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
authType | string | 是 | 令牌的鑒權(quán)類型。 |
token | string | 是 | 令牌的取值。 |
account9+ | 否 | 令牌所屬的帳號(hào)信息。 |
表示OAuth認(rèn)證器信息。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
owner | string | 是 | 認(rèn)證器的所有者包名。 |
iconId | number | 是 | 認(rèn)證器的圖標(biāo)標(biāo)識(shí)。 |
labelId | number | 是 | 認(rèn)證器的標(biāo)簽標(biāo)識(shí)。 |
表示認(rèn)證結(jié)果信息。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
account | 否 | 令牌所屬的帳號(hào)信息。 | |
tokenInfo | 否 | 令牌信息。 |
表示創(chuàng)建帳號(hào)的選項(xiàng)。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
customData | {[key: string]: string} | 否 | 自定義數(shù)據(jù)。 |
表示隱式創(chuàng)建帳號(hào)的選項(xiàng)。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
requiredLabels | Array<string> | 否 | 必須的標(biāo)簽。 |
authType | string | 否 | 鑒權(quán)類型。 |
parameters | {[key: string]: Object} | 否 | 自定義參數(shù)對(duì)象。 |
表示用于選擇帳號(hào)的選項(xiàng)。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
allowedAccounts | Array<AppAccountInfo> | 否 | 允許的帳號(hào)數(shù)組。 |
allowedOwners | Array<string> | 否 | 允許的帳號(hào)所有者數(shù)組。 |
requiredLabels | Array<string> | 否 | 認(rèn)證器的標(biāo)簽標(biāo)識(shí)。 |
表示用于驗(yàn)證憑據(jù)的選項(xiàng)。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
credentialType | string | 否 | 憑據(jù)類型。 |
credential | string | 否 | 憑據(jù)取值。 |
parameters | {[key: string]: Object} | 否 | 自定義參數(shù)對(duì)象。 |
表示用于設(shè)置屬性的選項(xiàng)。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
properties | {[key: string]: Object} | 否 | 屬性對(duì)象。 |
parameters | {[key: string]: Object} | 否 | 自定義參數(shù)對(duì)象。 |
表示常量的枚舉。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 值 | 說明 |
---|---|---|
ACTION_ADD_ACCOUNT_IMPLICITLY(deprecated) | "addAccountImplicitly" | 表示操作,隱式添加帳號(hào)。 |
ACTION_AUTHENTICATE(deprecated) | "authenticate" | 表示操作,鑒權(quán)。 |
ACTION_CREATE_ACCOUNT_IMPLICITLY9+ | "createAccountImplicitly" | 表示操作,隱式創(chuàng)建帳號(hào)。 |
ACTION_AUTH9+ | "auth" | 表示操作,鑒權(quán)。 |
ACTION_VERIFY_CREDENTIAL9+ | "verifyCredential" | 表示操作,驗(yàn)證憑據(jù)。 |
ACTION_SET_AUTHENTICATOR_PROPERTIES9+ | "setAuthenticatorProperties" | 表示操作,設(shè)置認(rèn)證器屬性。 |
KEY_NAME | "name" | 表示鍵名,應(yīng)用帳號(hào)的名稱。 |
KEY_OWNER | "owner" | 表示鍵名,應(yīng)用帳號(hào)所有者。 |
KEY_TOKEN | "token" | 表示鍵名,令牌。 |
KEY_ACTION | "action" | 表示鍵名,操作。 |
KEY_AUTH_TYPE | "authType" | 表示鍵名,鑒權(quán)類型。 |
KEY_SESSION_ID | "sessionId" | 表示鍵名,會(huì)話標(biāo)識(shí)。 |
KEY_CALLER_PID | "callerPid" | 表示鍵名,調(diào)用方PID。 |
KEY_CALLER_UID | "callerUid" | 表示鍵名,調(diào)用方UID。 |
KEY_CALLER_BUNDLE_NAME | "callerBundleName" | 表示鍵名,調(diào)用方包名。 |
KEY_REQUIRED_LABELS9+ | "requiredLabels" | 表示鍵名,必需的標(biāo)簽。 |
KEY_BOOLEAN_RESULT9+ | "booleanResult" | 表示鍵名,布爾返回值。 |
表示返回碼的枚舉。
從API version 8開始支持,從API version 9開始廢棄。相關(guān)信息建議查看錯(cuò)誤碼文檔替代。
系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。
名稱 | 值 | 說明 |
---|---|---|
SUCCESS | 0 | 表示操作成功。 |
ERROR_ACCOUNT_NOT_EXIST | 10001 | 表示應(yīng)用帳號(hào)不存在。 |
ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | 表示應(yīng)用帳號(hào)服務(wù)異常。 |
ERROR_INVALID_PASSWORD | 10003 | 表示密碼無效。 |
ERROR_INVALID_REQUEST | 10004 | 表示請(qǐng)求無效。 |
ERROR_INVALID_RESPONSE | 10005 | 表示響應(yīng)無效。 |
ERROR_NETWORK_EXCEPTION | 10006 | 表示網(wǎng)絡(luò)異常。 |
ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST | 10007 | 表示認(rèn)證器不存在。 |
ERROR_OAUTH_CANCELED | 10008 | 表示鑒權(quán)取消。 |
ERROR_OAUTH_LIST_TOO_LARGE | 10009 | 表示開放授權(quán)列表過大。 |
ERROR_OAUTH_SERVICE_BUSY | 10010 | 表示開放授權(quán)服務(wù)忙碌。 |
ERROR_OAUTH_SERVICE_EXCEPTION | 10011 | 表示開放授權(quán)服務(wù)異常。 |
ERROR_OAUTH_SESSION_NOT_EXIST | 10012 | 表示鑒權(quán)會(huì)話不存在。 |
ERROR_OAUTH_TIMEOUT | 10013 | 表示鑒權(quán)超時(shí)。 |
ERROR_OAUTH_TOKEN_NOT_EXIST | 10014 | 表示開放授權(quán)令牌不存在。 |
ERROR_OAUTH_TOKEN_TOO_MANY | 10015 | 表示開放授權(quán)令牌過多。 |
ERROR_OAUTH_UNSUPPORT_ACTION | 10016 | 表示不支持的鑒權(quán)操作。 |
ERROR_OAUTH_UNSUPPORT_AUTH_TYPE | 10017 | 表示不支持的鑒權(quán)類型。 |
ERROR_PERMISSION_DENIED | 10018 | 表示權(quán)限不足。 |
onResult: (code: number, result?: AuthResult) => void
通知請(qǐng)求結(jié)果。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
code | number | 是 | 鑒權(quán)結(jié)果碼。 |
result | 否 | 鑒權(quán)結(jié)果。 |
示例:
- let appAccountManager = account_appAccount.createAppAccountManager();
- var sessionId = "1234";
- appAccountManager.getAuthCallback(sessionId).then((callback) => {
- var result = {
- accountInfo: {
- name: "Lisi",
- owner: "com.example.accountjsdemo",
- },
- tokenInfo: {
- token: "xxxxxx",
- authType: "getSocialData"
- }
- };
- callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
- }).catch((err) => {
- console.log("getAuthCallback err: " + JSON.stringify(err));
- });
onRequestRedirected: (request: Want) => void
通知請(qǐng)求被跳轉(zhuǎn)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
request | Want | 是 | 用于跳轉(zhuǎn)的請(qǐng)求信息。 |
示例:
- class MyAuthenticator extends account_appAccount.Authenticator {
- createAccountImplicitly(options, callback) {
- callback.onRequestRedirected({
- bundleName: "com.example.accountjsdemo",
- abilityName: "com.example.accountjsdemo.LoginAbility",
- });
- }
- auth(name, authType, options, callback) {
- var result = {
- accountInfo: {
- name: "Lisi",
- owner: "com.example.accountjsdemo",
- },
- tokenInfo: {
- token: "xxxxxx",
- authType: "getSocialData"
- }
- };
- callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
- }
- }
onRequestContinued?: () => void
通知請(qǐng)求被繼續(xù)處理。
系統(tǒng)能力: SystemCapability.Account.AppAccount
示例:
- let appAccountManager = account_appAccount.createAppAccountManager();
- var sessionId = "1234";
- appAccountManager.getAuthCallback(sessionId).then((callback) => {
- callback.onRequestContinued();
- }).catch((err) => {
- console.log("getAuthCallback err: " + JSON.stringify(err));
- });
OAuth認(rèn)證器回調(diào)接口。
從 API version 8開始支持,從API version 9開始廢棄。建議使用AuthCallback替代。
onResult: (code: number, result: {[key: string]: any}) => void
通知請(qǐng)求結(jié)果。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
code | number | 是 | 鑒權(quán)結(jié)果碼。 |
result | {[key: string]: any} | 是 | 鑒權(quán)結(jié)果。 |
示例:
- let appAccountManager = account_appAccount.createAppAccountManager();
- var sessionId = "1234";
- appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
- var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
- [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo",
- [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
- [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
- callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
- }).catch((err) => {
- console.log("getAuthenticatorCallback err: " + JSON.stringify(err));
- });
onRequestRedirected: (request: Want) => void
通知請(qǐng)求被跳轉(zhuǎn)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
request | Want | 是 | 用于跳轉(zhuǎn)的請(qǐng)求信息。 |
示例:
- class MyAuthenticator extends account_appAccount.Authenticator {
- addAccountImplicitly(authType, callerBundleName, options, callback) {
- callback.onRequestRedirected({
- bundleName: "com.example.accountjsdemo",
- abilityName: "com.example.accountjsdemo.LoginAbility",
- });
- }
- authenticate(name, authType, callerBundleName, options, callback) {
- var result = {[account_appAccount.Constants.KEY_NAME]: name,
- [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
- [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
- callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
- }
- }
onRequestContinued?: () => void
通知請(qǐng)求被繼續(xù)處理。
系統(tǒng)能力: SystemCapability.Account.AppAccount
示例:
- let appAccountManager = account_appAccount.createAppAccountManager();
- var sessionId = "1234";
- appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
- callback.onRequestContinued();
- }).catch((err) => {
- console.log("getAuthenticatorCallback err: " + JSON.stringify(err));
- });
createAccountImplicitly(options: CreateAccountImplicitlyOptions, callback: AuthCallback): void
根據(jù)指定的帳號(hào)所有者隱式地創(chuàng)建應(yīng)用帳號(hào),并使用callback異步回調(diào)返回結(jié)果。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
options | 是 | 隱式創(chuàng)建帳號(hào)的選項(xiàng)。 | |
callback | 是 | 認(rèn)證器回調(diào)對(duì)象,用于返回創(chuàng)建結(jié)果。 |
addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
根據(jù)指定的鑒權(quán)類型和可選項(xiàng),隱式地添加應(yīng)用帳號(hào),并使用callback異步回調(diào)返回結(jié)果。
從 API version 8開始支持, 從API version 9開始廢棄。建議使用createAccountImplicitly替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
authType | string | 是 | 應(yīng)用帳號(hào)的鑒權(quán)類型。 |
callerBundleName | string | 是 | 鑒權(quán)請(qǐng)求方的包名。 |
options | {[key: string]: any} | 是 | 鑒權(quán)所需要的可選項(xiàng)。 |
callback | 是 | 認(rèn)證器回調(diào),用于返回鑒權(quán)結(jié)果。 |
auth(name: string, authType: string, options: {[key:string]: Object}, callback: AuthCallback): void
對(duì)應(yīng)用帳號(hào)進(jìn)行鑒權(quán)以獲取授權(quán)令牌,并使用callback異步回調(diào)返回結(jié)果。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 應(yīng)用帳號(hào)的鑒權(quán)類型。 |
callerBundleName | string | 是 | 鑒權(quán)類型。 |
options | {[key: string]: Object} | 是 | 鑒權(quán)所需要的可選項(xiàng)。 |
callback | 是 | 回調(diào)對(duì)象,用于返回鑒權(quán)結(jié)果。 |
authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
對(duì)應(yīng)用帳號(hào)進(jìn)行鑒權(quán),獲取OAuth令牌,并使用callback異步回調(diào)返回結(jié)果。
從 API version 8開始支持, 從API version 9開始廢棄。建議使用auth替代。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
authType | string | 是 | 應(yīng)用帳號(hào)的鑒權(quán)類型。 |
callerBundleName | string | 是 | 鑒權(quán)請(qǐng)求方的包名。 |
options | {[key: string]: any} | 是 | 鑒權(quán)所需要的可選項(xiàng)。 |
callback | 是 | 認(rèn)證器回調(diào),用于返回鑒權(quán)結(jié)果。 |
verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthCallback): void;
驗(yàn)證應(yīng)用帳號(hào)的憑據(jù),并使用callback異步回調(diào)返回結(jié)果。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
options | 是 | 驗(yàn)證憑據(jù)的可選項(xiàng)。 | |
callback | 是 | 認(rèn)證器回調(diào),用于返回驗(yàn)證結(jié)果。 |
setProperties(options: SetPropertiesOptions, callback: AuthCallback): void;
設(shè)置認(rèn)證器屬性,并使用callback異步回調(diào)返回結(jié)果。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
options | 是 | 設(shè)置屬性的可選項(xiàng)。 | |
callback | 是 | 認(rèn)證器回調(diào),用于返回設(shè)置結(jié)果。 |
checkAccountLabels(name: string, labels: Array<string>, callback: AuthCallback): void;
檢查帳號(hào)標(biāo)簽,并使用callback異步回調(diào)返回結(jié)果。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
labels | Array<string> | 是 | 標(biāo)簽數(shù)組。 |
callback | 是 | 認(rèn)證器回調(diào),用于返回檢查結(jié)果。 |
checkAccountRemovable(name: string, callback: AuthCallback): void;
判斷帳號(hào)是否可以刪除,并使用callback異步回調(diào)返回結(jié)果。
系統(tǒng)能力: SystemCapability.Account.AppAccount
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 應(yīng)用帳號(hào)的名稱。 |
callback | 是 | 認(rèn)證器回調(diào),用于返回判斷結(jié)果。 |
getRemoteObject(): rpc.RemoteObject;
獲取認(rèn)證器的遠(yuǎn)程對(duì)象,不可以重載實(shí)現(xiàn)。
系統(tǒng)能力: SystemCapability.Account.AppAccount
示例:
- class MyAuthenticator extends account_appAccount.Authenticator {
- addAccountImplicitly(authType, callerBundleName, options, callback) {
- callback.onRequestRedirected({
- bundleName: "com.example.accountjsdemo",
- abilityName: "com.example.accountjsdemo.LoginAbility",
- });
- }
- authenticate(name, authType, callerBundleName, options, callback) {
- var result = {[account_appAccount.Constants.KEY_NAME]: name,
- [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
- [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
- callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
- }
- verifyCredential(name, options, callback) {
- callback.onRequestRedirected({
- bundleName: "com.example.accountjsdemo",
- abilityName: "com.example.accountjsdemo.VerifyAbility",
- parameters: {
- name: name
- }
- });
- }
- setProperties(options, callback) {
- callback.onResult(account_appAccount.ResultCode.SUCCESS, {});
- }
- checkAccountLabels(name, labels, callback) {
- var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: false};
- callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
- }
- checkAccountRemovable(name, callback) {
- var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: true};
- callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
- }
- }
- var authenticator = null;
- export default {
- onConnect(want) {
- authenticator = new MyAuthenticator();
- return authenticator.getRemoteObject();
- }
- }
更多建議: