應(yīng)用帳號(hào)管理

2024-01-23 17:53 更新

本模塊提供應(yīng)用帳號(hào)信息的添加、刪除、修改和查詢基礎(chǔ)能力,并支持應(yīng)用間鑒權(quán)和分布式數(shù)據(jù)同步功能。

說明

本模塊首批接口從API version 7開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。

導(dǎo)入模塊

  1. import account_appAccount from '@ohos.account.appAccount';

account_appAccount.createAppAccountManager

createAppAccountManager(): AppAccountManager

創(chuàng)建應(yīng)用帳號(hào)管理器對(duì)象。

系統(tǒng)能力: SystemCapability.Account.AppAccount

返回值:

類型

說明

AppAccountManager

應(yīng)用帳號(hào)管理器對(duì)象。

示例:

  1. let appAccountManager = account_appAccount.createAppAccountManager();

AppAccountManager

應(yīng)用帳號(hào)管理器類。

createAccount9+

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.

示例:

  1. try {
  2. appAccountManager.createAccount("WangWu", (err) => {
  3. console.log("createAccount err: " + JSON.stringify(err));
  4. });
  5. } catch (err) {
  6. console.log("createAccount err: " + JSON.stringify(err));
  7. }

createAccount9+

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

CreateAccountOptions

創(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.

示例:

  1. let options = {
  2. customData: {
  3. "age": "10"
  4. }
  5. }
  6. try {
  7. appAccountManager.createAccount("LiSi", options, (err) => {
  8. if (err) {
  9. console.log("createAccount failed, error: " + JSON.stringify(err));
  10. } else {
  11. console.log("createAccount successfully");
  12. }
  13. });
  14. } catch(err) {
  15. console.log("createAccount exception: " + JSON.stringify(err));
  16. }

createAccount9+

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

CreateAccountOptions

創(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.

示例:

  1. let options = {
  2. customData: {
  3. "age": "10"
  4. }
  5. }
  6. try {
  7. appAccountManager.createAccount("LiSi", options).then(() => {
  8. console.log("createAccount successfully");
  9. }).catch((err) => {
  10. console.log("createAccount failed, error: " + JSON.stringify(err));
  11. });
  12. } catch(err) {
  13. console.log("createAccount exception: " + JSON.stringify(err));
  14. }

createAccountImplicitly9+

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

AuthCallback

認(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.

示例:

  1. function onResultCallback(code, result) {
  2. console.log("resultCode: " + code);
  3. console.log("result: " + JSON.stringify(result));
  4. }
  5. function onRequestRedirectedCallback(request) {
  6. let wantInfo = {
  7. deviceId: '',
  8. bundleName: 'com.example.accountjsdemo',
  9. action: 'ohos.want.action.viewData',
  10. entities: ['entity.system.default'],
  11. }
  12. this.context.startAbility(wantInfo).then(() => {
  13. console.log("startAbility successfully");
  14. }).catch((err) => {
  15. console.log("startAbility err: " + JSON.stringify(err));
  16. })
  17. }
  18. try {
  19. appAccountManager.createAccountImplicitly("com.example.accountjsdemo", {
  20. onResult: onResultCallback,
  21. onRequestRedirected: onRequestRedirectedCallback
  22. });
  23. } catch (err) {
  24. console.log("createAccountImplicitly exception: " + JSON.stringify(err));
  25. }

createAccountImplicitly9+

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

CreateAccountImplicitlyOptions

隱式創(chuàng)建帳號(hào)的選項(xiàng)。

callback

AuthCallback

認(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.

示例:

  1. function onResultCallback(code, result) {
  2. console.log("resultCode: " + code);
  3. console.log("result: " + JSON.stringify(result));
  4. }
  5. function onRequestRedirectedCallback(request) {
  6. let wantInfo = {
  7. deviceId: '',
  8. bundleName: 'com.example.accountjsdemo',
  9. action: 'ohos.want.action.viewData',
  10. entities: ['entity.system.default'],
  11. }
  12. this.context.startAbility(wantInfo).then(() => {
  13. console.log("startAbility successfully");
  14. }).catch((err) => {
  15. console.log("startAbility err: " + JSON.stringify(err));
  16. })
  17. }
  18. let options = {
  19. authType: "getSocialData",
  20. requiredLabels: [ "student" ]
  21. };
  22. try {
  23. appAccountManager.createAccountImplicitly("com.example.accountjsdemo", options, {
  24. onResult: onResultCallback,
  25. onRequestRedirected: onRequestRedirectedCallback
  26. });
  27. } catch (err) {
  28. console.log("createAccountImplicitly exception: " + JSON.stringify(err));
  29. }

removeAccount9+

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.

示例:

  1. try {
  2. appAccountManager.removeAccount("ZhaoLiu", (err) => {
  3. if (err) {
  4. console.log("removeAccount failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log("removeAccount successfully");
  7. }
  8. });
  9. } catch(err) {
  10. console.log("removeAccount exception: " + JSON.stringify(err));
  11. }

removeAccount9+

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.

示例:

  1. try {
  2. appAccountManager.removeAccount("Lisi").then(() => {
  3. console.log("removeAccount successfully");
  4. }).catch((err) => {
  5. console.log("removeAccount failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("removeAccount exception: " + JSON.stringify(err));
  9. }

setAppAccess9+

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.

示例:

  1. try {
  2. appAccountManager.setAppAccess("ZhangSan", "com.example.accountjsdemo", true, (err) => {
  3. if (err) {
  4. console.log("setAppAccess failed: " + JSON.stringify(err));
  5. } else {
  6. console.log("setAppAccess successfully");
  7. }
  8. });
  9. } catch (err) {
  10. console.log("setAppAccess exception: " + JSON.stringify(err));
  11. }

setAppAccess9+

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.

示例:

  1. try {
  2. appAccountManager.setAppAccess("ZhangSan", "com.example.accountjsdemo", true).then(() => {
  3. console.log("setAppAccess successfully");
  4. }).catch((err) => {
  5. console.log("setAppAccess failed: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("setAppAccess exception: " + JSON.stringify(err));
  9. }

checkAppAccess9+

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.

示例:

  1. try {
  2. appAccountManager.checkAppAccess("ZhangSan", "com.example.accountjsdemo", (err, isAccessible) => {
  3. if (err) {
  4. console.log("checkAppAccess failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log("checkAppAccess successfully");
  7. }
  8. });
  9. } catch (err) {
  10. console.log("checkAppAccess exception: " + JSON.stringify(err));
  11. }

checkAppAccess9+

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.

示例:

  1. try {
  2. appAccountManager.checkAppAccess("ZhangSan", "com.example.accountjsdemo").then((isAccessible) => {
  3. console.log("checkAppAccess successfully, isAccessible: " + isAccessible);
  4. }).catch((err) => {
  5. console.log("checkAppAccess failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("checkAppAccess exception: " + JSON.stringify(err));
  9. }

setDataSyncEnabled9+

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.

示例:

  1. try {
  2. appAccountManager.setDataSyncEnabled("ZhangSan", true, (err) => {
  3. console.log("setDataSyncEnabled err: " + JSON.stringify(err));
  4. });
  5. } catch (err) {
  6. console.log("setDataSyncEnabled err: " + JSON.stringify(err));
  7. }

setDataSyncEnabled9+

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.

示例:

  1. try {
  2. appAccountManager .setDataSyncEnabled("ZhangSan", true).then(() => {
  3. console.log('setDataSyncEnabled Success');
  4. }).catch((err) => {
  5. console.log("setDataSyncEnabled err: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("setDataSyncEnabled err: " + JSON.stringify(err));
  9. }

checkDataSyncEnabled9+

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.

示例:

  1. try {
  2. appAccountManager.checkDataSyncEnabled("ZhangSan", (err, isEnabled) => {
  3. if (err) {
  4. console.log("checkDataSyncEnabled failed, err: " + JSON.stringify(err));
  5. } else {
  6. console.log('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled);
  7. }
  8. });
  9. } catch (err) {
  10. console.log("checkDataSyncEnabled err: " + JSON.stringify(err));
  11. }

checkDataSyncEnabled9+

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.

示例:

  1. try {
  2. appAccountManager.checkDataSyncEnabled("ZhangSan").then((isEnabled) => {
  3. console.log("checkDataSyncEnabled successfully, isEnabled: " + isEnabled);
  4. }).catch((err) => {
  5. console.log("checkDataSyncEnabled failed, err: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("checkDataSyncEnabled err: " + JSON.stringify(err));
  9. }

setCredential9+

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.

示例:

  1. try {
  2. appAccountManager.setCredential("ZhangSan", "PIN_SIX", "xxxxxx", (err) => {
  3. if (err) {
  4. console.log("setCredential failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log("setCredential successfully");
  7. }
  8. });
  9. } catch (err) {
  10. console.log("setCredential exception: " + JSON.stringify(err));
  11. }

setCredential9+

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.

示例:

  1. try {
  2. appAccountManager.setCredential("ZhangSan", "PIN_SIX", "xxxxxx").then(() => {
  3. console.log("setCredential successfully");
  4. }).catch((err) => {
  5. console.log("setCredential failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("setCredential exception: " + JSON.stringify(err));
  9. }

getCredential9+

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.

示例:

  1. try {
  2. appAccountManager.getCredential("ZhangSan", "PIN_SIX", (err, result) => {
  3. if (err) {
  4. console.log("getCredential failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log('getCredential successfully, result: ' + result);
  7. }
  8. });
  9. } catch (err) {
  10. console.log("getCredential err: " + JSON.stringify(err));
  11. }

getCredential9+

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.

示例:

  1. try {
  2. appAccountManager.getCredential("ZhangSan", "PIN_SIX").then((credential) => {
  3. console.log("getCredential successfully, credential: " + credential);
  4. }).catch((err) => {
  5. console.log("getCredential failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("getCredential exception: " + JSON.stringify(err));
  9. }

setCustomData9+

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.

示例:

  1. try {
  2. appAccountManager.setCustomData("ZhangSan", "age", "12", (err) => {
  3. if (err) {
  4. console.log("setCustomData failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log("setCustomData successfully");
  7. }
  8. });
  9. } catch (err) {
  10. console.log("setCustomData exception: " + JSON.stringify(err));
  11. }

setCustomData9+

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.

示例:

  1. try {
  2. appAccountManager.setCustomData("ZhangSan", "age", "12").then(() => {
  3. console.log("setCustomData successfully");
  4. }).catch((err) => {
  5. console.log("setCustomData failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("setCustomData exception: " + JSON.stringify(err));
  9. }

getCustomData9+

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.

示例:

  1. try {
  2. appAccountManager.getCustomData("ZhangSan", "age", (err, data) => {
  3. if (err) {
  4. console.log('getCustomData failed, error: ' + err);
  5. } else {
  6. console.log("getCustomData successfully, data: " + data);
  7. }
  8. });
  9. } catch (err) {
  10. console.log("getCustomData exception: " + JSON.stringify(err));
  11. }

getCustomData9+

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.

示例:

  1. try {
  2. appAccountManager.getCustomData("ZhangSan", "age").then((data) => {
  3. console.log("getCustomData successfully, data: " + data);
  4. }).catch((err) => {
  5. console.log("getCustomData failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("getCustomData exception: " + JSON.stringify(err));
  9. }

getCustomDataSync9+

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.

示例:

  1. try {
  2. let value = appAccountManager.getCustomDataSync("ZhangSan", "age");
  3. console.info("getCustomDataSync successfully, vaue:" + value);
  4. } catch (err) {
  5. console.error("getCustomDataSync failed, error: " + JSON.stringify(err));
  6. }

getAllAccounts9+

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.

示例:

  1. try {
  2. appAccountManager.getAllAccounts((err, data) => {
  3. if (err) {
  4. console.debug("getAllAccounts failed, error:" + JSON.stringify(err));
  5. } else {
  6. console.debug("getAllAccounts successfully");
  7. }
  8. });
  9. } catch (err) {
  10. console.debug("getAllAccounts exception: " + JSON.stringify(err));
  11. }

getAllAccounts9+

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.

示例:

  1. try {
  2. appAccountManager.getAllAccounts().then((data) => {
  3. console.debug("getAllAccounts successfully");
  4. }).catch((err) => {
  5. console.debug("getAllAccounts failed, error:" + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.debug("getAllAccounts exception: " + JSON.stringify(err));
  9. }

getAccountsByOwner9+

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.

示例:

  1. try {
  2. appAccountManager.getAccountsByOwner("com.example.accountjsdemo2", (err, data) => {
  3. if (err) {
  4. console.debug("getAccountsByOwner failed, error:" + JSON.stringify(err));
  5. } else {
  6. console.debug("getAccountsByOwner successfully, data:" + JSON.stringify(data));
  7. }
  8. });
  9. } catch (err) {
  10. console.debug("getAccountsByOwner exception:" + JSON.stringify(err));
  11. }

getAccountsByOwner9+

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.

示例:

  1. try {
  2. appAccountManager.getAccountsByOwner("com.example.accountjsdemo2").then((data) => {
  3. console.debug("getAccountsByOwner successfully, data:" + JSON.stringify(data));
  4. }).catch((err) => {
  5. console.debug("getAccountsByOwner failed, error:" + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.debug("getAccountsByOwner exception:" + JSON.stringify(err));
  9. }

on('accountChange')9+

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.

示例:

  1. function changeOnCallback(data){
  2. console.log("receive change data:" + JSON.stringify(data));
  3. }
  4. try{
  5. appAccountManager.on("accountChange", ["com.example.actsaccounttest"], changeOnCallback);
  6. } catch(err) {
  7. console.error("on accountChange failed, error:" + JSON.stringify(err));
  8. }

off('accountChange')9+

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.

示例:

  1. function changeOnCallback(data){
  2. console.log("receive change data:" + JSON.stringify(data));
  3. }
  4. try{
  5. appAccountManager.on("accountChange", ["com.example.actsaccounttest"], changeOnCallback);
  6. } catch(err) {
  7. console.error("on accountChange failed, error:" + JSON.stringify(err));
  8. }
  9. try{
  10. appAccountManager.off('accountChange', changeOnCallback);
  11. }
  12. catch(err){
  13. console.error("off accountChange failed, error:" + JSON.stringify(err));
  14. }

auth9+

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

AuthCallback

回調(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.

示例:

  1. function onResultCallback(code, authResult) {
  2. console.log("resultCode: " + code);
  3. console.log("authResult: " + JSON.stringify(authResult));
  4. }
  5. function onRequestRedirectedCallback(request) {
  6. let wantInfo = {
  7. deviceId: '',
  8. bundleName: 'com.example.accountjsdemo',
  9. action: 'ohos.want.action.viewData',
  10. entities: ['entity.system.default'],
  11. }
  12. this.context.startAbility(wantInfo).then(() => {
  13. console.log("startAbility successfully");
  14. }).catch((err) => {
  15. console.log("startAbility err: " + JSON.stringify(err));
  16. })
  17. }
  18. try {
  19. appAccountManager.auth("LiSi", "com.example.accountjsdemo", "getSocialData", {
  20. onResult: onResultCallback,
  21. onRequestRedirected: onRequestRedirectedCallback
  22. });
  23. } catch (err) {
  24. console.log("auth exception: " + JSON.stringify(err));
  25. }

auth9+

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

AuthCallback

回調(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.

示例:

  1. function onResultCallback(code, authResult) {
  2. console.log("resultCode: " + code);
  3. console.log("authResult: " + JSON.stringify(authResult));
  4. }
  5. function onRequestRedirectedCallback(request) {
  6. let wantInfo = {
  7. deviceId: '',
  8. bundleName: 'com.example.accountjsdemo',
  9. action: 'ohos.want.action.viewData',
  10. entities: ['entity.system.default'],
  11. }
  12. this.context.startAbility(wantInfo).then(() => {
  13. console.log("startAbility successfully");
  14. }).catch((err) => {
  15. console.log("startAbility err: " + JSON.stringify(err));
  16. })
  17. }
  18. let options = {
  19. "password": "xxxx",
  20. };
  21. try {
  22. appAccountManager.auth("LiSi", "com.example.accountjsdemo", "getSocialData", options, {
  23. onResult: onResultCallback,
  24. onRequestRedirected: onRequestRedirectedCallback
  25. });
  26. } catch (err) {
  27. console.log("auth exception: " + JSON.stringify(err));
  28. }

getAuthToken9+

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.

示例:

  1. try {
  2. appAccountManager.getAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", (err, token) => {
  3. if (err) {
  4. console.log("getAuthToken failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log("getAuthToken successfully, token: " + token);
  7. }
  8. });
  9. } catch (err) {
  10. console.log("getAuthToken exception: " + JSON.stringify(err));
  11. }

getAuthToken9+

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.

示例:

  1. try {
  2. appAccountManager.getAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData").then((token) => {
  3. console.log("getAuthToken successfully, token: " + token);
  4. }).catch((err) => {
  5. console.log("getAuthToken failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("getAuthToken exception: " + JSON.stringify(err));
  9. }

setAuthToken9+

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.

示例:

  1. try {
  2. appAccountManager.setAuthToken("LiSi", "getSocialData", "xxxx", (err) => {
  3. if (err) {
  4. console.log("setAuthToken failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log("setAuthToken successfully");
  7. }
  8. });
  9. } catch (err) {
  10. console.log('setAuthToken exception: ' + JSON.stringify(err));
  11. }

setAuthToken9+

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.

示例:

  1. try {
  2. appAccountManager.setAuthToken("LiSi", "getSocialData", "xxxx").then(() => {
  3. console.log("setAuthToken successfully");
  4. }).catch((err) => {
  5. console.log("setAuthToken failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("setAuthToken exception: " + JSON.stringify(err));
  9. }

deleteAuthToken9+

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.

示例:

  1. try {
  2. appAccountManager.deleteAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx", (err) => {
  3. if (err) {
  4. console.log('deleteAuthToken failed, error: ' + JSON.stringify(err));
  5. } else {
  6. console.log("deleteAuthToken successfully");
  7. }
  8. });
  9. } catch (err) {
  10. console.log('deleteAuthToken exception: ' + JSON.stringify(err));
  11. }

deleteAuthToken9+

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.

示例:

  1. try {
  2. appAccountManager.deleteAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx").then(() => {
  3. console.log("deleteAuthToken successfully");
  4. }).catch((err) => {
  5. console.log('deleteAuthToken failed, error: ' + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log('deleteAuthToken exception: ' + JSON.stringify(err));
  9. }

setAuthTokenVisibility9+

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.

示例:

  1. try {
  2. appAccountManager.setAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true, (err) => {
  3. if (err) {
  4. console.log("setAuthTokenVisibility failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log("setAuthTokenVisibility successfully");
  7. }
  8. });
  9. } catch (err) {
  10. console.log("setAuthTokenVisibility exception: " + JSON.stringify(err));
  11. }

setAuthTokenVisibility9+

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.

示例:

  1. try {
  2. appAccountManager.setAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true).then(() => {
  3. console.log("setAuthTokenVisibility successfully");
  4. }).catch((err) => {
  5. console.log("setAuthTokenVisibility failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("setAuthTokenVisibility exception: " + JSON.stringify(err));
  9. }

checkAuthTokenVisibility9+

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.

示例:

  1. try {
  2. appAccountManager.checkAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", (err, isVisible) => {
  3. if (err) {
  4. console.log("checkAuthTokenVisibility failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log("checkAuthTokenVisibility successfully, isVisible: " + isVisible);
  7. }
  8. });
  9. } catch (err) {
  10. console.log("checkAuthTokenVisibility exception: " + JSON.stringify(err));
  11. }

checkAuthTokenVisibility9+

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.

示例:

  1. try {
  2. appAccountManager.checkAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo").then((isVisible) => {
  3. console.log("checkAuthTokenVisibility successfully, isVisible: " + isVisible);
  4. }).catch((err) => {
  5. console.log("checkAuthTokenVisibility failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("checkAuthTokenVisibility exception: " + JSON.stringify(err));
  9. }

getAllAuthTokens9+

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.

示例:

  1. try {
  2. appAccountManager.getAllAuthTokens("LiSi", "com.example.accountjsdemo", (err, tokenArr) => {
  3. if (err) {
  4. console.log("getAllAuthTokens failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log('getAllAuthTokens successfully, tokenArr: ' + tokenArr);
  7. }
  8. });
  9. } catch (err) {
  10. console.log("getAllAuthTokens exception: " + JSON.stringify(err));
  11. }

getAllAuthTokens9+

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.

示例:

  1. try {
  2. appAccountManager.getAllAuthTokens("LiSi", "com.example.accountjsdemo").then((tokenArr) => {
  3. console.log('getAllAuthTokens successfully, tokenArr: ' + JSON.stringify(tokenArr));
  4. }).catch((err) => {
  5. console.log("getAllAuthTokens failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("getAllAuthTokens exception: " + JSON.stringify(err));
  9. }

getAuthList9+

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.

示例:

  1. try {
  2. appAccountManager.getAuthList("com.example.accountjsdemo", "getSocialData", (err, authList) => {
  3. if (err) {
  4. console.log("getAuthList failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log("getAuthList successfully, authList: " + authList);
  7. }
  8. });
  9. } catch (err) {
  10. console.log('getAuthList exception: ' + JSON.stringify(err));
  11. }

getAuthList9+

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.

示例:

  1. try {
  2. appAccountManager.getAuthList("com.example.accountjsdemo", "getSocialData").then((authList) => {
  3. console.log("getAuthList successfully, authList: " + authList);
  4. }).catch((err) => {
  5. console.log("getAuthList failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("getAuthList exception: " + JSON.stringify(err));
  9. }

getAuthCallback9+

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.

示例:

  1. import UIAbility from '@ohos.app.ability.UIAbility';
  2. export default class EntryAbility extends UIAbility {
  3. onCreate(want, param) {
  4. var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
  5. try {
  6. appAccountManager.getAuthCallback(sessionId, (err, callback) => {
  7. if (err != null) {
  8. console.log("getAuthCallback err: " + JSON.stringify(err));
  9. return;
  10. }
  11. var result = {
  12. accountInfo: {
  13. name: "Lisi",
  14. owner: "com.example.accountjsdemo",
  15. },
  16. tokenInfo: {
  17. token: "xxxxxx",
  18. authType: "getSocialData"
  19. }
  20. };
  21. callback.onResult(0, result);
  22. });
  23. } catch (err) {
  24. console.log("getAuthCallback exception: " + JSON.stringify(err));
  25. }
  26. }
  27. }

getAuthCallback9+

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.

示例:

  1. import UIAbility from '@ohos.app.ability.UIAbility';
  2. export default class EntryAbility extends UIAbility {
  3. onCreate(want, param) {
  4. var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
  5. try {
  6. appAccountManager.getAuthCallback(sessionId).then((callback) => {
  7. var result = {
  8. accountInfo: {
  9. name: "Lisi",
  10. owner: "com.example.accountjsdemo",
  11. },
  12. tokenInfo: {
  13. token: "xxxxxx",
  14. authType: "getSocialData"
  15. }
  16. };
  17. callback.onResult(0, result);
  18. }).catch((err) => {
  19. console.log("getAuthCallback err: " + JSON.stringify(err));
  20. });
  21. } catch (err) {
  22. console.log("getAuthCallback exception: " + JSON.stringify(err));
  23. }
  24. }
  25. }

queryAuthenticatorInfo9+

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.

示例:

  1. try {
  2. appAccountManager.queryAuthenticatorInfo("com.example.accountjsdemo", (err, info) => {
  3. if (err) {
  4. console.log("queryAuthenticatorInfo failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info));
  7. }
  8. });
  9. } catch (err) {
  10. console.log("queryAuthenticatorInfo exception: " + JSON.stringify(err));
  11. }

queryAuthenticatorInfo9+

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.

示例:

  1. try {
  2. appAccountManager.queryAuthenticatorInfo("com.example.accountjsdemo").then((info) => {
  3. console.log("queryAuthenticatorInfo successfully, info: " + JSON.stringify(info));
  4. }).catch((err) => {
  5. console.log("queryAuthenticatorInfo failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("queryAuthenticatorInfo exception: " + JSON.stringify(err));
  9. }

checkAccountLabels9+

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.

示例:

  1. let labels = ["student"];
  2. try {
  3. appAccountManager.checkAccountLabels("zhangsan", "com.example.accountjsdemo", labels, (err, hasAllLabels) => {
  4. if (err) {
  5. console.log("checkAccountLabels failed, error: " + JSON.stringify(err));
  6. } else {
  7. console.log("checkAccountLabels successfully, hasAllLabels: " + hasAllLabels);
  8. }
  9. });
  10. } catch (err) {
  11. console.log("checkAccountLabels exception: " + JSON.stringify(err));
  12. }

checkAccountLabels9+

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.

示例:

  1. let labels = ["student"];
  2. try {
  3. appAccountManager.checkAccountLabels("zhangsan", "com.example.accountjsdemo", labels).then((hasAllLabels) => {
  4. console.log('checkAccountLabels successfully: ' + hasAllLabels);
  5. }).catch((err) => {
  6. console.log("checkAccountLabels failed, error: " + JSON.stringify(err));
  7. });
  8. } catch (err) {
  9. console.log("checkAccountLabels exception: " + JSON.stringify(err));
  10. }

deleteCredential9+

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.

示例:

  1. try {
  2. appAccountManager.deleteCredential("zhangsan", "PIN_SIX", (err) => {
  3. if (err) {
  4. console.log("deleteCredential failed, error: " + JSON.stringify(err));
  5. } else {
  6. console.log("deleteCredential successfully");
  7. }
  8. });
  9. } catch (err) {
  10. console.log("deleteCredential exception: " + JSON.stringify(err));
  11. }

deleteCredential9+

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.

示例:

  1. try {
  2. appAccountManager.deleteCredential("zhangsan", "PIN_SIX").then(() => {
  3. console.log("deleteCredential successfully");
  4. }).catch((err) => {
  5. console.log("deleteCredential failed, error: " + JSON.stringify(err));
  6. });
  7. } catch (err) {
  8. console.log("deleteCredential exception: " + JSON.stringify(err));
  9. }

selectAccountsByOptions9+

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.

示例:

  1. let options = {
  2. allowedOwners: [ "com.example.accountjsdemo" ],
  3. requiredLabels: [ "student" ]
  4. };
  5. try {
  6. appAccountManager.selectAccountsByOptions(options, (err, accountArr) => {
  7. if (err) {
  8. console.log("selectAccountsByOptions failed, error: " + JSON.stringify(err));
  9. } else {
  10. console.log("selectAccountsByOptions successfully, accountArr: " + JSON.stringify(accountArr));
  11. }
  12. });
  13. } catch (err) {
  14. console.log("selectAccountsByOptions exception: " + JSON.stringify(err));
  15. }

selectAccountsByOptions9+

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

SelectAccountsOptions

選擇帳號(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.

示例:

  1. let options = {
  2. allowedOwners: ["com.example.accountjsdemo"]
  3. };
  4. try {
  5. appAccountManager.selectAccountsByOptions(options).then((accountArr) => {
  6. console.log("selectAccountsByOptions successfully, accountArr: " + JSON.stringify(accountArr));
  7. }).catch((err) => {
  8. console.log("selectAccountsByOptions failed, error: " + JSON.stringify(err));
  9. });
  10. } catch (err) {
  11. console.log("selectAccountsByOptions exception: " + JSON.stringify(err));
  12. }

verifyCredential9+

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

AuthCallback

回調(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.

示例:

  1. try {
  2. appAccountManager.verifyCredential("zhangsan", "com.example.accountjsdemo", {
  3. onResult: (resultCode, result) => {
  4. console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode));
  5. console.log("verifyCredential onResult, result:" + JSON.stringify(result));
  6. },
  7. onRequestRedirected: (request) => {
  8. console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request));
  9. }
  10. });
  11. } catch (err) {
  12. console.log("verifyCredential err: " + JSON.stringify(err));
  13. }

verifyCredential9+

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

VerifyCredentialOptions

驗(yàn)證憑據(jù)的選項(xiàng)。

callback

AuthCallback

回調(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.

示例:

  1. let options = {
  2. credentialType: "pin",
  3. credential: "123456"
  4. };
  5. try {
  6. appAccountManager.verifyCredential("zhangsan", "com.example.accountjsdemo", options, {
  7. onResult: (resultCode, result) => {
  8. console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode));
  9. console.log("verifyCredential onResult, result:" + JSON.stringify(result));
  10. },
  11. onRequestRedirected: (request) => {
  12. console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request));
  13. }
  14. });
  15. } catch (err) {
  16. console.log("verifyCredential err: " + JSON.stringify(err));
  17. }

setAuthenticatorProperties9+

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

AuthCallback

回調(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.

示例:

  1. try {
  2. appAccountManager.setAuthenticatorProperties("com.example.accountjsdemo", {
  3. onResult: (resultCode, result) => {
  4. console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode));
  5. console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result));
  6. },
  7. onRequestRedirected: (request) => {
  8. console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request));
  9. }
  10. });
  11. } catch (err) {
  12. console.log("setAuthenticatorProperties err: " + JSON.stringify(err));
  13. }

setAuthenticatorProperties9+

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

SetPropertiesOptions

設(shè)置屬性的選項(xiàng)。

callback

AuthCallback

認(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.

示例:

  1. let options = {
  2. properties: {"prop1": "value1"}
  3. };
  4. try {
  5. appAccountManager.setAuthenticatorProperties("com.example.accountjsdemo", options, {
  6. onResult: (resultCode, result) => {
  7. console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode));
  8. console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result));
  9. },
  10. onRequestRedirected: (request) => {
  11. console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request));
  12. }
  13. });
  14. } catch (err) {
  15. console.log("setAuthenticatorProperties err: " + JSON.stringify(err));
  16. }

addAccount(deprecated)

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ì)象。

示例:

  1. appAccountManager.addAccount("WangWu", (err) => {
  2. console.log("addAccount err: " + JSON.stringify(err));
  3. });

addAccount(deprecated)

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ì)象。

示例:

  1. appAccountManager.addAccount("LiSi", "token101", (err) => {
  2. console.log("addAccount err: " + JSON.stringify(err));
  3. });

addAccount(deprecated)

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ì)象。

示例:

  1. appAccountManager.addAccount("LiSi", "token101").then(()=> {
  2. console.log('addAccount Success');
  3. }).catch((err) => {
  4. console.log("addAccount err: " + JSON.stringify(err));
  5. });

addAccountImplicitly(deprecated)

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

AuthenticatorCallback

認(rèn)證器回調(diào)對(duì)象,返回添加結(jié)果。

示例:

  1. function onResultCallback(code, result) {
  2. console.log("resultCode: " + code);
  3. console.log("result: " + JSON.stringify(result));
  4. }
  5. function onRequestRedirectedCallback(request) {
  6. let wantInfo = {
  7. deviceId: '',
  8. bundleName: 'com.example.accountjsdemo',
  9. action: 'ohos.want.action.viewData',
  10. entities: ['entity.system.default'],
  11. }
  12. this.context.startAbility(wantInfo).then(() => {
  13. console.log("startAbility successfully");
  14. }).catch((err) => {
  15. console.log("startAbility err: " + JSON.stringify(err));
  16. })
  17. }
  18. appAccountManager.addAccountImplicitly("com.example.accountjsdemo", "getSocialData", {}, {
  19. onResult: onResultCallback,
  20. onRequestRedirected: onRequestRedirectedCallback
  21. });

deleteAccount(deprecated)

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ì)象。

示例:

  1. appAccountManager.deleteAccount("ZhaoLiu", (err) => {
  2. console.log("deleteAccount err: " + JSON.stringify(err));
  3. });

deleteAccount(deprecated)

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ì)象。

示例:

  1. appAccountManager.deleteAccount("ZhaoLiu").then(() => {
  2. console.log('deleteAccount Success');
  3. }).catch((err) => {
  4. console.log("deleteAccount err: " + JSON.stringify(err));
  5. });

disableAppAccess(deprecated)

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ì)象。

示例:

  1. appAccountManager.disableAppAccess("ZhangSan", "com.example.accountjsdemo", (err) => {
  2. console.log("disableAppAccess err: " + JSON.stringify(err));
  3. });

disableAppAccess(deprecated)

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ì)象。

示例:

  1. appAccountManager.disableAppAccess("ZhangSan", "com.example.accountjsdemo").then(() => {
  2. console.log('disableAppAccess Success');
  3. }).catch((err) => {
  4. console.log("disableAppAccess err: " + JSON.stringify(err));
  5. });

enableAppAccess(deprecated)

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ì)象。

示例:

  1. appAccountManager.enableAppAccess("ZhangSan", "com.example.accountjsdemo", (err) => {
  2. console.log("enableAppAccess: " + JSON.stringify(err));
  3. });

enableAppAccess(deprecated)

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ì)象。

示例:

  1. appAccountManager.enableAppAccess("ZhangSan", "com.example.accountjsdemo").then(() => {
  2. console.log('enableAppAccess Success');
  3. }).catch((err) => {
  4. console.log("enableAppAccess err: " + JSON.stringify(err));
  5. });

checkAppAccountSyncEnable(deprecated)

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表示未開啟。

示例:

  1. appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => {
  2. console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err));
  3. console.log('checkAppAccountSyncEnable result: ' + result);
  4. });

checkAppAccountSyncEnable(deprecated)

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表示未開啟。

示例:

  1. appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => {
  2. console.log('checkAppAccountSyncEnable, result: ' + data);
  3. }).catch((err) => {
  4. console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err));
  5. });

setAccountCredential(deprecated)

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ì)象。

示例:

  1. appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => {
  2. console.log("setAccountCredential err: " + JSON.stringify(err));
  3. });

setAccountCredential(deprecated)

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ì)象。

示例:

  1. appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => {
  2. console.log('setAccountCredential Success');
  3. }).catch((err) => {
  4. console.log("setAccountCredential err: " + JSON.stringify(err));
  5. });

setAccountExtraInfo(deprecated)

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ì)象。

示例:

  1. appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => {
  2. console.log("setAccountExtraInfo err: " + JSON.stringify(err));
  3. });

setAccountExtraInfo(deprecated)

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ì)象。

示例:

  1. appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => {
  2. console.log('setAccountExtraInfo Success');
  3. }).catch((err) => {
  4. console.log("setAccountExtraInfo err: " + JSON.stringify(err));
  5. });

setAppAccountSyncEnable(deprecated)

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ì)象。

示例:

  1. appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => {
  2. console.log("setAppAccountSyncEnable err: " + JSON.stringify(err));
  3. });

setAppAccountSyncEnable(deprecated)

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ì)象。

示例:

  1. appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => {
  2. console.log('setAppAccountSyncEnable Success');
  3. }).catch((err) => {
  4. console.log("setAppAccountSyncEnable err: " + JSON.stringify(err));
  5. });

setAssociatedData(deprecated)

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ì)象。

示例:

  1. appAccountManager.setAssociatedData("ZhangSan", "k001", "v001", (err) => {
  2. console.log("setAssociatedData err: " + JSON.stringify(err));
  3. });

setAssociatedData(deprecated)

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ì)象。

示例:

  1. appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => {
  2. console.log('setAssociatedData Success');
  3. }).catch((err) => {
  4. console.log("setAssociatedData err: " + JSON.stringify(err));
  5. });

getAllAccessibleAccounts(deprecated)

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ì)象。

示例:

  1. appAccountManager.getAllAccessibleAccounts((err, data)=>{
  2. console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err));
  3. console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data));
  4. });

getAllAccessibleAccounts(deprecated)

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ì)象。

示例:

  1. appAccountManager.getAllAccessibleAccounts().then((data) => {
  2. console.log('getAllAccessibleAccounts: ' + data);
  3. }).catch((err) => {
  4. console.log("getAllAccessibleAccounts err: " + JSON.stringify(err));
  5. });

getAllAccounts(deprecated)

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)信息列表。

示例:

  1. const selfBundle = "com.example.actsgetallaaccounts";
  2. appAccountManager.getAllAccounts(selfBundle, (err, data)=>{
  3. console.debug("getAllAccounts err:" + JSON.stringify(err));
  4. console.debug("getAllAccounts data:" + JSON.stringify(data));
  5. });

getAllAccounts(deprecated)

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ì)象。

示例:

  1. const selfBundle = "com.example.actsgetallaaccounts";
  2. appAccountManager.getAllAccounts(selfBundle).then((data) => {
  3. console.log('getAllAccounts: ' + data);
  4. }).catch((err) => {
  5. console.log("getAllAccounts err: " + JSON.stringify(err));
  6. });

getAccountCredential(deprecated)

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ì)象。

示例:

  1. appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => {
  2. console.log("getAccountCredential err: " + JSON.stringify(err));
  3. console.log('getAccountCredential result: ' + result);
  4. });

getAccountCredential(deprecated)

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ù)。

示例:

  1. appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => {
  2. console.log('getAccountCredential, result: ' + data);
  3. }).catch((err) => {
  4. console.log("getAccountCredential err: " + JSON.stringify(err));
  5. });

getAccountExtraInfo(deprecated)

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ì)象。

示例:

  1. appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => {
  2. console.log("getAccountExtraInfo err: " + JSON.stringify(err));
  3. console.log('getAccountExtraInfo result: ' + result);
  4. });

getAccountExtraInfo(deprecated)

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ì)象。

示例:

  1. appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => {
  2. console.log('getAccountExtraInfo, result: ' + data);
  3. }).catch((err) => {
  4. console.log("getAccountExtraInfo err: " + JSON.stringify(err));
  5. });

getAssociatedData(deprecated)

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ì)象。

示例:

  1. appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => {
  2. console.log("getAssociatedData err: " + JSON.stringify(err));
  3. console.log('getAssociatedData result: ' + result);
  4. });

getAssociatedData(deprecated)

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ù)的取值。

示例:

  1. appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => {
  2. console.log('getAssociatedData: ' + data);
  3. }).catch((err) => {
  4. console.log("getAssociatedData err: " + JSON.stringify(err));
  5. });

on('change')(deprecated)

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)列表。

示例:

  1. function changeOnCallback(data){
  2. console.debug("receive change data:" + JSON.stringify(data));
  3. }
  4. try{
  5. appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
  6. }
  7. catch(err){
  8. console.error("on accountOnOffDemo err:" + JSON.stringify(err));
  9. }

off('change')(deprecated)

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)列表。

示例:

  1. function changeOnCallback(data){
  2. console.debug("receive change data:" + JSON.stringify(data));
  3. appAccountManager.off('change', function(){
  4. console.debug("off finish");
  5. })
  6. }
  7. try{
  8. appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
  9. }
  10. catch(err){
  11. console.error("on accountOnOffDemo err:" + JSON.stringify(err));
  12. }

authenticate(deprecated)

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

AuthenticatorCallback

回調(diào)對(duì)象,返回鑒權(quán)結(jié)果。

示例:

  1. function onResultCallback(code, result) {
  2. console.log("resultCode: " + code);
  3. console.log("result: " + JSON.stringify(result));
  4. }
  5. function onRequestRedirectedCallback(request) {
  6. let wantInfo = {
  7. deviceId: '',
  8. bundleName: 'com.example.accountjsdemo',
  9. action: 'ohos.want.action.viewData',
  10. entities: ['entity.system.default'],
  11. }
  12. this.context.startAbility(wantInfo).then(() => {
  13. console.log("startAbility successfully");
  14. }).catch((err) => {
  15. console.log("startAbility err: " + JSON.stringify(err));
  16. })
  17. }
  18. appAccountManager.authenticate("LiSi", "com.example.accountjsdemo", "getSocialData", {}, {
  19. onResult: onResultCallback,
  20. onRequestRedirected: onRequestRedirectedCallback
  21. });

getOAuthToken(deprecated)

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ì)象。

示例:

  1. appAccountManager.getOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", (err, data) => {
  2. console.log('getOAuthToken err: ' + JSON.stringify(err));
  3. console.log('getOAuthToken token: ' + data);
  4. });

getOAuthToken(deprecated)

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)令牌。

示例:

  1. appAccountManager.getOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData").then((data) => {
  2. console.log('getOAuthToken token: ' + data);
  3. }).catch((err) => {
  4. console.log("getOAuthToken err: " + JSON.stringify(err));
  5. });

setOAuthToken(deprecated)

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ì)象。

示例:

  1. appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx", (err) => {
  2. console.log('setOAuthToken err: ' + JSON.stringify(err));
  3. });

setOAuthToken(deprecated)

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ì)象。

示例:

  1. appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx").then(() => {
  2. console.log('setOAuthToken successfully');
  3. }).catch((err) => {
  4. console.log('setOAuthToken err: ' + JSON.stringify(err));
  5. });

deleteOAuthToken(deprecated)

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ì)象。

示例:

  1. appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx", (err) => {
  2. console.log('deleteOAuthToken err: ' + JSON.stringify(err));
  3. });

deleteOAuthToken(deprecated)

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ì)象。

示例:

  1. appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx").then(() => {
  2. console.log('deleteOAuthToken successfully');
  3. }).catch((err) => {
  4. console.log("deleteOAuthToken err: " + JSON.stringify(err));
  5. });

setOAuthTokenVisibility(deprecated)

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ì)象。

示例:

  1. appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true, (err) => {
  2. console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
  3. });

setOAuthTokenVisibility(deprecated)

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ì)象。

示例:

  1. appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true).then(() => {
  2. console.log('setOAuthTokenVisibility successfully');
  3. }).catch((err) => {
  4. console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
  5. });

checkOAuthTokenVisibility(deprecated)

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ì)象。

示例:

  1. appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", (err, data) => {
  2. console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
  3. console.log('checkOAuthTokenVisibility isVisible: ' + data);
  4. });

checkOAuthTokenVisibility(deprecated)

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表示不可見。

示例:

  1. appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo").then((data) => {
  2. console.log('checkOAuthTokenVisibility isVisible: ' + data);
  3. }).catch((err) => {
  4. console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
  5. });

getAllOAuthTokens(deprecated)

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ì)象。

示例:

  1. appAccountManager.getAllOAuthTokens("LiSi", "com.example.accountjsdemo", (err, data) => {
  2. console.log("getAllOAuthTokens err: " + JSON.stringify(err));
  3. console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
  4. });

getAllOAuthTokens(deprecated)

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ù)組。

示例:

  1. appAccountManager.getAllOAuthTokens("LiSi", "com.example.accountjsdemo").then((data) => {
  2. console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
  3. }).catch((err) => {
  4. console.log("getAllOAuthTokens err: " + JSON.stringify(err));
  5. });

getOAuthList(deprecated)

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ì)象。

示例:

  1. appAccountManager.getOAuthList("com.example.accountjsdemo", "getSocialData", (err, data) => {
  2. console.log('getOAuthList err: ' + JSON.stringify(err));
  3. console.log('getOAuthList data: ' + JSON.stringify(data));
  4. });

getOAuthList(deprecated)

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ù)組。

示例:

  1. appAccountManager.getOAuthList("com.example.accountjsdemo", "getSocialData").then((data) => {
  2. console.log('getOAuthList data: ' + JSON.stringify(data));
  3. }).catch((err) => {
  4. console.log("getOAuthList err: " + JSON.stringify(err));
  5. });

getAuthenticatorCallback(deprecated)

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ì)象。

示例:

  1. import UIAbility from '@ohos.app.ability.UIAbility';
  2. export default class EntryAbility extends UIAbility {
  3. onCreate(want, param) {
  4. var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
  5. appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => {
  6. if (err.code != account_appAccount.ResultCode.SUCCESS) {
  7. console.log("getAuthenticatorCallback err: " + JSON.stringify(err));
  8. return;
  9. }
  10. var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
  11. [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo",
  12. [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
  13. [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
  14. callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
  15. });
  16. }
  17. }

getAuthenticatorCallback(deprecated)

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ì)象。

示例:

  1. import UIAbility from '@ohos.app.ability.UIAbility';
  2. export default class EntryAbility extends UIAbility {
  3. onCreate(want, param) {
  4. var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
  5. appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
  6. var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
  7. [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo",
  8. [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
  9. [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
  10. callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
  11. }).catch((err) => {
  12. console.log("getAuthenticatorCallback err: " + JSON.stringify(err));
  13. });
  14. }
  15. }

getAuthenticatorInfo(deprecated)

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ì)象。

示例:

  1. appAccountManager.getAuthenticatorInfo("com.example.accountjsdemo", (err, data) => {
  2. console.log("getAuthenticatorInfo err: " + JSON.stringify(err));
  3. console.log('getAuthenticatorInfo data: ' + JSON.stringify(data));
  4. });

getAuthenticatorInfo(deprecated)

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ì)象。

示例:

  1. appAccountManager.getAuthenticatorInfo("com.example.accountjsdemo").then((data) => {
  2. console.log('getAuthenticatorInfo: ' + JSON.stringify(data));
  3. }).catch((err) => {
  4. console.log("getAuthenticatorInfo err: " + JSON.stringify(err));
  5. });

AppAccountInfo

表示應(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)的名稱。

AuthTokenInfo9+

表示Auth令牌信息。

系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。

名稱

類型

必填

說明

authType9+

string

令牌的鑒權(quán)類型。

token9+

string

令牌的取值。

account9+

AppAccountInfo

令牌所屬的帳號(hào)信息。

OAuthTokenInfo(deprecated)

表示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+

AppAccountInfo

令牌所屬的帳號(hào)信息。

AuthenticatorInfo8+

表示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í)。

AuthResult9+

表示認(rèn)證結(jié)果信息。

系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。

名稱

類型

必填

說明

account

AppAccountInfo

令牌所屬的帳號(hào)信息。

tokenInfo

AuthTokenInfo

令牌信息。

CreateAccountOptions9+

表示創(chuàng)建帳號(hào)的選項(xiàng)。

系統(tǒng)能力: 以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Account.AppAccount。

名稱

類型

必填

說明

customData

{[key: string]: string}

自定義數(shù)據(jù)。

CreateAccountImplicitlyOptions9+

表示隱式創(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ì)象。

SelectAccountsOptions9+

表示用于選擇帳號(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í)。

VerifyCredentialOptions9+

表示用于驗(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ì)象。

SetPropertiesOptions9+

表示用于設(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ì)象。

Constants8+

表示常量的枚舉。

系統(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"

表示鍵名,布爾返回值。

ResultCode(deprecated)

表示返回碼的枚舉。

說明

從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)限不足。

AuthCallback9+

認(rèn)證器回調(diào)類。

onResult9+

onResult: (code: number, result?: AuthResult) => void

通知請(qǐng)求結(jié)果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名

類型

必填

說明

code

number

鑒權(quán)結(jié)果碼。

result

AuthResult

鑒權(quán)結(jié)果。

示例:

  1. let appAccountManager = account_appAccount.createAppAccountManager();
  2. var sessionId = "1234";
  3. appAccountManager.getAuthCallback(sessionId).then((callback) => {
  4. var result = {
  5. accountInfo: {
  6. name: "Lisi",
  7. owner: "com.example.accountjsdemo",
  8. },
  9. tokenInfo: {
  10. token: "xxxxxx",
  11. authType: "getSocialData"
  12. }
  13. };
  14. callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
  15. }).catch((err) => {
  16. console.log("getAuthCallback err: " + JSON.stringify(err));
  17. });

onRequestRedirected9+

onRequestRedirected: (request: Want) => void

通知請(qǐng)求被跳轉(zhuǎn)。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名

類型

必填

說明

request

Want

用于跳轉(zhuǎn)的請(qǐng)求信息。

示例:

  1. class MyAuthenticator extends account_appAccount.Authenticator {
  2. createAccountImplicitly(options, callback) {
  3. callback.onRequestRedirected({
  4. bundleName: "com.example.accountjsdemo",
  5. abilityName: "com.example.accountjsdemo.LoginAbility",
  6. });
  7. }
  8. auth(name, authType, options, callback) {
  9. var result = {
  10. accountInfo: {
  11. name: "Lisi",
  12. owner: "com.example.accountjsdemo",
  13. },
  14. tokenInfo: {
  15. token: "xxxxxx",
  16. authType: "getSocialData"
  17. }
  18. };
  19. callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
  20. }
  21. }

onRequestContinued9+

onRequestContinued?: () => void

通知請(qǐng)求被繼續(xù)處理。

系統(tǒng)能力: SystemCapability.Account.AppAccount

示例:

  1. let appAccountManager = account_appAccount.createAppAccountManager();
  2. var sessionId = "1234";
  3. appAccountManager.getAuthCallback(sessionId).then((callback) => {
  4. callback.onRequestContinued();
  5. }).catch((err) => {
  6. console.log("getAuthCallback err: " + JSON.stringify(err));
  7. });

AuthenticatorCallback(deprecated)

OAuth認(rèn)證器回調(diào)接口。

說明

從 API version 8開始支持,從API version 9開始廢棄。建議使用AuthCallback替代。

onResult8+

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é)果。

示例:

  1. let appAccountManager = account_appAccount.createAppAccountManager();
  2. var sessionId = "1234";
  3. appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
  4. var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
  5. [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo",
  6. [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
  7. [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
  8. callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
  9. }).catch((err) => {
  10. console.log("getAuthenticatorCallback err: " + JSON.stringify(err));
  11. });

onRequestRedirected8+

onRequestRedirected: (request: Want) => void

通知請(qǐng)求被跳轉(zhuǎn)。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名

類型

必填

說明

request

Want

用于跳轉(zhuǎn)的請(qǐng)求信息。

示例:

  1. class MyAuthenticator extends account_appAccount.Authenticator {
  2. addAccountImplicitly(authType, callerBundleName, options, callback) {
  3. callback.onRequestRedirected({
  4. bundleName: "com.example.accountjsdemo",
  5. abilityName: "com.example.accountjsdemo.LoginAbility",
  6. });
  7. }
  8. authenticate(name, authType, callerBundleName, options, callback) {
  9. var result = {[account_appAccount.Constants.KEY_NAME]: name,
  10. [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
  11. [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
  12. callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
  13. }
  14. }

onRequestContinued9+

onRequestContinued?: () => void

通知請(qǐng)求被繼續(xù)處理。

系統(tǒng)能力: SystemCapability.Account.AppAccount

示例:

  1. let appAccountManager = account_appAccount.createAppAccountManager();
  2. var sessionId = "1234";
  3. appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
  4. callback.onRequestContinued();
  5. }).catch((err) => {
  6. console.log("getAuthenticatorCallback err: " + JSON.stringify(err));
  7. });

Authenticator8+

認(rèn)證器基類。

createAccountImplicitly9+

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

CreateAccountImplicitlyOptions

隱式創(chuàng)建帳號(hào)的選項(xiàng)。

callback

AuthCallback

認(rèn)證器回調(diào)對(duì)象,用于返回創(chuàng)建結(jié)果。

addAccountImplicitly(deprecated)

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

AuthenticatorCallback

認(rèn)證器回調(diào),用于返回鑒權(quán)結(jié)果。

auth9+

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

AuthCallback

回調(diào)對(duì)象,用于返回鑒權(quán)結(jié)果。

authenticate(deprecated)

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

AuthenticatorCallback

認(rèn)證器回調(diào),用于返回鑒權(quán)結(jié)果。

verifyCredential9+

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

VerifyCredentialOptions

驗(yàn)證憑據(jù)的可選項(xiàng)。

callback

AuthCallback

認(rèn)證器回調(diào),用于返回驗(yàn)證結(jié)果。

setProperties9+

setProperties(options: SetPropertiesOptions, callback: AuthCallback): void;

設(shè)置認(rèn)證器屬性,并使用callback異步回調(diào)返回結(jié)果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名

類型

必填

說明

options

SetPropertiesOptions

設(shè)置屬性的可選項(xiàng)。

callback

AuthCallback

認(rèn)證器回調(diào),用于返回設(shè)置結(jié)果。

checkAccountLabels9+

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

AuthCallback

認(rèn)證器回調(diào),用于返回檢查結(jié)果。

checkAccountRemovable9+

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

AuthCallback

認(rèn)證器回調(diào),用于返回判斷結(jié)果。

getRemoteObject9+

getRemoteObject(): rpc.RemoteObject;

獲取認(rèn)證器的遠(yuǎn)程對(duì)象,不可以重載實(shí)現(xiàn)。

系統(tǒng)能力: SystemCapability.Account.AppAccount

示例:

  1. class MyAuthenticator extends account_appAccount.Authenticator {
  2. addAccountImplicitly(authType, callerBundleName, options, callback) {
  3. callback.onRequestRedirected({
  4. bundleName: "com.example.accountjsdemo",
  5. abilityName: "com.example.accountjsdemo.LoginAbility",
  6. });
  7. }
  8. authenticate(name, authType, callerBundleName, options, callback) {
  9. var result = {[account_appAccount.Constants.KEY_NAME]: name,
  10. [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
  11. [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
  12. callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
  13. }
  14. verifyCredential(name, options, callback) {
  15. callback.onRequestRedirected({
  16. bundleName: "com.example.accountjsdemo",
  17. abilityName: "com.example.accountjsdemo.VerifyAbility",
  18. parameters: {
  19. name: name
  20. }
  21. });
  22. }
  23. setProperties(options, callback) {
  24. callback.onResult(account_appAccount.ResultCode.SUCCESS, {});
  25. }
  26. checkAccountLabels(name, labels, callback) {
  27. var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: false};
  28. callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
  29. }
  30. checkAccountRemovable(name, callback) {
  31. var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: true};
  32. callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
  33. }
  34. }
  35. var authenticator = null;
  36. export default {
  37. onConnect(want) {
  38. authenticator = new MyAuthenticator();
  39. return authenticator.getRemoteObject();
  40. }
  41. }
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)