我在使用游戏服务时很痛苦。
我创建一个页首横幅,然后根据Scores: list进行
GET https://www.googleapis.com/games/v1/leaderboards/$LEADERBOARD_ID/scores/PUBLIC?timeSpan=ALL_TIME
返回
{
kind: games#leaderboardScores,
numScores: 0
}
似乎还可以, 然后我想提交一个分数,所以根据Scores: submit,我要做
POST https://www.googleapis.com/games/v1/leaderboards/$LEADERBOARD_ID/scores?score=$score
但答案是
code: 401, message: There is no linked app associated with this client ID.
我已在Play控制台上链接,重新链接,重新链接了该应用程序,但它根本无法正常工作, 同样的问题也出现在Scores: get
GET https://www.googleapis.com/games/v1/players/$id/leaderboards/$LEADERBOARD_ID/scores/ALL_TIME
如果有人知道如何解决此问题,谢谢您的帮助。
顺便说一下,这是我的代码:
import 'dart:convert';
import "package:http/http.dart" as http;
import 'package:google_sign_in/google_sign_in.dart';
import 'package:BallPhobia/playgames.dart';
class PlayServices {
static const LEADERBOARD_ID='MY_LEADERBOARD_ID';
static final GoogleSignIn _googleSignIn = GoogleSignIn(signInOption: SignInOption.games,scopes: ['https://www.googleapis.com/auth/games']);
static GoogleSignInAccount account;
static Map<String, dynamic> userData;
static Future singIn() async {
account = await _googleSignIn.signIn();
final http.Response response = await http.get(
'https://www.googleapis.com/games/v1/players/me',
headers: await account.authHeaders,
);
userData = json.decode(response.body);
print(userData);
}
static Future<ScoreResults> loadScores() async {
final http.Response response = await http.get(
'https://www.googleapis.com/games/v1/leaderboards/$LEADERBOARD_ID/scores/PUBLIC?timeSpan=ALL_TIME',
headers: await account.authHeaders,
);
final Map<String, dynamic> data = json.decode(response.body);
print(data);
}
// returns code: 401, message: There is no linked app associated with this client ID.
static Future<ScoreResults> loadMyScores() async {
final id = userData['playerId'] ;
final http.Response response = await http.get(
'https://www.googleapis.com/games/v1/players/$id/leaderboards/$LEADERBOARD_ID/scores/ALL_TIME',
headers: await account.authHeaders,
);
final Map<String, dynamic> data = json.decode(response.body);
print(data);
}
// returns code: 401, message: There is no linked app associated with this client ID.
static Future writeScore(int score) async {
final http.Response response = await http.post(
'https://www.googleapis.com/games/v1/leaderboards/$LEADERBOARD_ID/scores?score=$score',
headers: await account.authHeaders,
);
final Map<String, dynamic> data = json.decode(response.body);
print(data);
}
}