微信小游戏吸引人的地方就是可以获得好友的游戏数据,进行排名,我尝试获取,调用成功,但是结果报系统错误。
先用cocoscreator实现游戏逻辑
在cocoscreator项目里可以调用微信api,如下图
let openDataContext = wx.getOpenDataContext()
构建微信小程序,用微信开发者工具打开项目
1、在game.json里添加openDataContext:
"deviceOrientation": "landscape",
"openDataContext": "src/myOpenDataContext",
2、新建目录myOpenDataContext和js
调用回调报错:getFriendUserGameData:fail 系统错误,错误码:-2"
wx.onMessage(data => {
// console.log("************onMessage called")
let kvdata = [{key:"score",value:"12"}]
wx.setUserCloudStorage({
KVDataList:kvdata,
success: res =>{
console.log(res)
},fail: res => {
console.log(res)
}
})
let keyList = ["score"]
wx.getUserCloudStorage({
keyList: keyList,
success: res => {
let data = res.data
console.log(res)
},
fail: res => {
console.log(res)
}
})
wx.getFriendUserGameData({
keyList: keyList,
success: res => {
let data = res.data
drawRankList(data)
},
fail: res =>{
console.log(res)
}
})
})
网友评论