当前位置:   article > 正文

{errMsg: “getUserProfile:fail api scope is not declared in the privacy agreement“, errno: 112}

getuserprofile:fail api scope is not declared in the privacy agreement

首先登录小程序公众平台,在【设置-服务内容声明-用户隐私保护指引】,更新隐私协议,在第一条:开发者处理的信息中,点击【增加信息类型】,选择需要授权的信息,头像昵称我已经勾选了,所以列表中不显示了,根据需求选择和填写其他内容,最后确定并生成协议。等待隐私协议审核通过。

先创建一个组件

  1. <template>
  2. <view class="privacy" v-if="showPrivacy">
  3. <view class="content">
  4. <view class="title">隐私保护指引</view>
  5. <view class="des">
  6. 在使用当前小程序服务之前,请仔细阅读<text class="link" @tap="openPrivacyContract">{{ privacyContractName }}</text>。如你同意{{
  7. privacyContractName }},请点击“同意”开始使用。
  8. </view>
  9. <view class="btns">
  10. <button class="item reject" @tap="exitMiniProgram">拒绝</button>
  11. <button id="agree-btn" class="item agree" open-type="agreePrivacyAuthorization"
  12. @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. privacyContractName: '《隐私保护引导》',
  22. showPrivacy: false
  23. }
  24. },
  25. created() {
  26. this.checkPrivacySetting();
  27. },
  28. methods: {
  29. checkPrivacySetting(){
  30. uni.getPrivacySetting({
  31. success: res => {
  32. console.log("getPrivacySetting",res)
  33. this.showPrivacy = true
  34. // needAuthorization是否需要用户授权隐私协议
  35. // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
  36. if (res.needAuthorization) {
  37. // 需要弹出隐私协议
  38. this.showPrivacy = true
  39. } else {
  40. this.showPrivacy = false
  41. // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
  42. // wx.getUserProfile()
  43. // wx.chooseMedia()
  44. // wx.getClipboardData()
  45. // wx.startRecord()
  46. }
  47. },
  48. fail: () => {},
  49. complete: () => {}
  50. })
  51. },
  52. // 打开隐私协议
  53. openPrivacyContract() {
  54. uni.openPrivacyContract({
  55. fail: () => {
  56. uni.showToast({
  57. title: '遇到错误',
  58. icon: 'error'
  59. })
  60. }
  61. })
  62. },
  63. // 拒绝隐私协议
  64. exitMiniProgram() {
  65. console.log("拒绝隐私协议")
  66. const that = this;
  67. // 直接退出小程序
  68. // wx.exitMiniProgram()
  69. uni.showModal({
  70. // 如果拒绝,我们将无法获取您的信息, 包括手机号、位置信息、相册等该小程序十分重要的功能,您确定要拒绝吗?
  71. content: '您确定要拒绝吗?',
  72. success: res => {
  73. if (res.confirm) {
  74. that.showPrivacy = false;
  75. uni.exitMiniProgram({
  76. success: () => {
  77. console.log('退出小程序成功');
  78. }
  79. });
  80. }
  81. }
  82. });
  83. },
  84. // 同意隐私协议
  85. handleAgreePrivacyAuthorization() {
  86. var that = this;
  87. wx.requirePrivacyAuthorize({
  88. success: () => {
  89. // 用户同意授权
  90. // 继续小程序逻辑
  91. that.showPrivacy = false;
  92. },
  93. fail: () => {}, // 用户拒绝授权
  94. complete: () => {}
  95. })
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped> .privacy {
  101. position: fixed;
  102. top: 0;
  103. right: 0;
  104. bottom: 0;
  105. left: 0;
  106. background: rgba(0, 0, 0, .5);
  107. z-index: 9999999;
  108. display: flex;
  109. align-items: center;
  110. justify-content: center;
  111. }
  112. .content {
  113. width: 632rpx;
  114. padding: 48rpx;
  115. box-sizing: border-box;
  116. background: #fff;
  117. border-radius: 16rpx;
  118. }
  119. .content .title {
  120. text-align: center;
  121. color: #333;
  122. font-weight: bold;
  123. font-size: 32rpx;
  124. }
  125. .content .des {
  126. font-size: 26rpx;
  127. color: #666;
  128. margin-top: 40rpx;
  129. text-align: justify;
  130. line-height: 1.6;
  131. }
  132. .content .des .link {
  133. color: #07c160;
  134. text-decoration: underline;
  135. }
  136. .btns {
  137. margin-top: 48rpx;
  138. display: flex;
  139. }
  140. .btns .item {
  141. justify-content: space-between;
  142. width: 244rpx;
  143. height: 80rpx;
  144. display: flex;
  145. align-items: center;
  146. justify-content: center;
  147. border-radius: 16rpx;
  148. box-sizing: border-box;
  149. border: none;
  150. }
  151. .btns .reject {
  152. background: #f4f4f5;
  153. color: #909399;
  154. }
  155. .btns .agree {
  156. background: #07c160;
  157. color: #fff;
  158. }
  159. </style>

在实际登录页面,引入组件,并调用checkPrivacySetting(),来检查用户是否需要授权隐私协议

  1. <privacy-pop ref="PrivacyPopck"></privacy-pop>
  2. import PrivacyPop from '../../components/PrivacyPop/PrivacyPop.vue';
  3. export default {
  4. name: 'sq-login',
  5. components:{
  6. PrivacyPop
  7. },
  8. data() {
  9. return {
  10. userName:'',
  11. avatarUrl:'',
  12. }
  13. },
  14. onLoad() {
  15. //调用组件的检测是否授权方法,就可以了
  16. this.$refs.PrivacyPopck.checkPrivacySetting();
  17. },
  18. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/616053
推荐阅读
相关标签
  

闽ICP备14008679号