How to submit the score in HUAWEI Unity Game service in Official plugin? - huawei-mobile-services

how to submit the scores for the leaderboard in Game service in Unity Platform.
While using the IGetLeaderboardsListener method the score always showing as 1. So in that case, how to submit the score there.

if you want to submit the score for leaderboard in unity,you can use:
HuaweiGameService.SubmitScore(string leaderboardId, int score)
unity document link:
https://docs.unity.cn/cn/Packages-cn/com.unity.huaweiservice#1.3/manual/gameservices.html
HuaweiGameService.SubmitScore(string leaderboardId, int score, string scoreTag)
Submit a score to a leaderboard for the currently signed-in player.
HuaweiGameService.AsyncSubmitScore(string leaderboardId, int score, string scoreTag, ISubmitScoreListener listener)
Submit a score to a leaderboard for the currently signed-in player, this method gets the callback asynchronously.

Related

Google play leaderboards not updating the score after new score has been reported

I have been struggling with this problem for a few days... I have google play services set up, my achievements work properly, but the leaderboard doesn't seem to want to work.
This is the code that reports new score to the leaderboard:
public static void AddScoreToLeaderboard(string LeaderboardId, long score) {
Social.ReportScore(score, LeaderboardId, success => { Debug.Log("Leaderboard updated: "+score); });
}
When the function is called i get the debug message saying that the leaderboard has been updated but when i go back to the leaderboard which i display with this:
public static void ShowLeaderboardsUI()
{
Social.ShowLeaderboardUI();
}
The leaderboard is completely empty...
Any help will be appreciated.
So another user on github suggested this and it worked for me.
I had same problem with my game but i resolved that.
Follow the steps carefully:
1-Go to https://console.developers.google.com/apis/credentials
2-Remove all credentials
3-Go to https://play.google.com/apps/publish
4-In all applications tab click on your game
5-Then from left menu click on Release Management and then go to App signing
6-Copy the code of SHA1 from the App signing certificate part
7-Go back to https://console.developers.google.com/apis/credentials
8-Create credentials and choose OAuth client ID
9-Choose application type (it was android for me!)
10-paste the code you copied from part 6 in Signing-certificate fingerprint field
11-Write the package name of the game exactly in Package name field the click on create
12-Go back to https://play.google.com/apps/publish
13-click on Game Services and then click on your game
14-Click on Link apps from left menu
15-click on Link another app
16-Choose your platform (android for me!)
17-write a name
18-click on Package name field and choose your package name there
19-save and publish the linked app that you just created
20-compare the OAuth2 Client ID from linked app that you just created with Client ID in credentials you created in part 11
21-if they have the same code the leaderboard will work fine!
Hope it solves your problem!

Problems with leaderboard using the facebook SDK

I am trying to make a leaderboard using the facebook unity sdk(for android devices in my case) I have most of the code down and it works just fine in the editor and on phone.
I can post my score as well as retrieve it in the editor using my access token.
I can also post and retrieve my score on an android where I logged in with my id.(the one to which the app is connected)
But here's the problem:
When I try logging in with another account I can neither post my score nor can I retrieve it.
though I can get the username, profile pic of the account with which I am logged in as No.1 but the score remains 0.
Even the score of my other account isn't visible in the leaderboard.
What I deduced:
As it's mentioned on the Scores API page you require the publish_actions permission to post scores I believe this is what I am missing. But this does not explain why I am unable to see my score posted from my (developer) account.
Is it that during testing with an access token or on a mobile device using the developer or administrator account I can only see my own score using the "AppID/scores?fields=scores"?
void SetScore()
{
score = //score
var ScoreData = new Dictionary<string, string>() {{"score", score.ToString()}};
FB.API("/me/scores", Facebook.HttpMethod.POST, publishActionCallback, ScoreData);
Debug.Log ("Score data" + ScoreData);
}
void publishActionCallback(FBResult result){ Debug.Log ("ScoreUpdated!");}
public void friendsScore()
{
FB.API("/MYAPPID/scores?fields=score",
Facebook.HttpMethod.GET, CallbackFriendScores);
//HTTP GET request for the scores
}
CallbackFriendScore(FBResult result){Debug.Log ("response GET: " +result.Text);//the real callback is different but the debug can be used to recreate the same problem}
Note: I am trying to use FB.API("/me/scores", Facebook.HttpMethod.POST, publishActionCallback, ScoreData)
and FB.API("/MYAPPID/scores", Facebook.HttpMethod.GET, CallbackFriendScores) to get the scores.

Make a facebook achievement visible in timeline

I can successfully publish a Facebook Achievement, but it only apears on my activity log.
There I have the option to change its visibility from "Allowed on timeline" to "Shown on timeline" or "Hidden from timeline".
When I change it to "Shown on timeline" it apears on my timeline, and that's the default behaviour I'd like to happen.
How can I change the default behaviour to "Shown on timeline"?
I'm using Unity (latest version: 5.4.2) and Facebook SDK for Unity (latest version: 5.1).
This is the relevant piece of code:
var query = new Dictionary<string, string>();
query["achievement"] = achievementUrl;
FB.API("/me/achievements", Facebook.HttpMethod.POST, callbackfunc, query);
Also, I wanted something similar for the Score, but in this case it is even worse.
When I publish a Score it just says in the activity log that I was playing game X - it doesn't even say I have a new highscore.
The code:
var query = new Dictionary<string, string>();
query["score"] = scoreString;
FB.API("/me/scores", Facebook.HttpMethod.POST, callbackfunc, query);
[Edit] - The score "story" is apearing in the activity log as well after all, so the problem is exactly the same as the achievements.
Facebook says:
This behavior is intended for the Achievement story and it's not meant to be shown on Timeline.
I recommend moving away from these implicit stories and integrate explicit stories where the user decides how and when to share back to Facebook.
Here's a guide on how to implement explicit sharing: https://developers.facebook.com/docs/opengraph/using-actions/v2.2#explicitsharing

Facebook Score API Highscores

I'm switching to Facebook Scores API for my mobile game's highscores. Like in this question, whose answer is not quite satisfying I would like to know how to seperate between:
Scores (The player finished a game and got a score below his actual highscore)
Highscores (The highscore of a particular player)
My current solution with Spring Social Facebook is:
MultiValueMap<String, String> data = new LinkedMultiValueMap<String, String>();
data.add("score", Integer.toString(score));
facebook.post("me", "scores", data);
The problem with this approach is:
I'm displaying a ranking for the user at the game-finished-screen by a comparison of his score to his friends scores via HTTP GET to GRAPH_API/APP_ID/scores
Imagine a user finished a game with Score 100, but his current highscore is 500. When I post this new score to the facebook API, subsequent calls for getting the score comparison return 100 as score, rather than 500, which should be his actual highscore.
How should I solve this? Posting only the highscores to Facebook means that I can't compare the actual score from the game-finished-screen to the users friends. On the other hand, posting actual scores would make it neccessary to store the highscores somewhere else than Facebook, or resign from showing the user his highscore, which does not seem to be a good solution to me.
I ended up checking if the current score is actually higher than the score on Facebook and only posting the new score if this check succeeds. Posting every score to Facebook does not work, because Facebook just saves the posted score and does not check if it is higher than the current uploaded score.
FacebookTemplate facebook = new FacebookTemplate(userAccessToken);
int highscore = queryScoreFromFacebook(facebook);
if (score > highscore) {
MultiValueMap<String, String> data = new LinkedMultiValueMap<String, String>();
data.add("score", Integer.toString(score));
facebook.post("me", "scores", data);
}
// querying all scores for that player and his friends
List<Map<String, Object>> players = (List<Map<String, Object>>) facebook.fetchObject("/" + APP_ID + "/scores", Map.class).get("data");
The Facebook Scores API only stores one (high) score per user and app at any time - if you want to track the score for other games you'll need to implement that yourself

Unity3D Facebook SDK Achievements

I'm trying to implement achievements with the Facebook Unity SDK.
I was hoping somebody could give me a qualitative description of the process required to do this.
Here's what I've done so far.
Hosted the web build on a server
Created an achievements folder on this site and created a test achievements html file as in https://developers.facebook.com/blog/post/539/
My main confusion is the difference between registering an achievement and positing an achievement.
Is registering an achievement something that needs to be done only once and if so where should this be done? Do I need to create a script in unity that registers all the achievements for the game that I run before the rest of my testing?
Also I'm unsure how the method call works for registering and posting an achievement. I'm under the impression I need to
call FB.API(string endpoint,Facebook.HttpMethod,FacebookDelegate callback,Dictionary formData)
but I'm really not sure what the input arguments need to be.
Here's my attempt so far(I'm pretty sure the string endpoint I've used is wrong)
private void RegisterAchievement()
{
string achievement ="http://www.invadingspaces.com/unity/testing/Achievements/ach1.html";
string appID = "999408935255000";
string achievement_display_order = "1";
string achievement_registration_URL = "https://graph.facebook.com/"+ appID + "/achievements";
FB.API(achievement_registration_URL+","+"achievement="+ achievement+ "&display_order=" +achievement_display_order+ "&access_token=" + FB.AccessToken ,Facebook.HttpMethod.POST,null,null);
}
Thanks in advance.
I'd suggest looking at the general Facebook achievements API: https://developers.facebook.com/docs/games/achievements/
Also you can first test out what to actually put with the graph explorer then put that into graph.:
https://developers.facebook.com/tools/explorer
So for example to create a new achivement it's just this:
var dict = new Dictionary<string,string>();
dict["achievement"] = "<URL_TO ACHIEVEMENT_HERE>";
FB.API(FB.AppId+"/achievements", Facebook.HttpMethod.POST, null, dict);
To get all your game achievements, it's:
FB.API(FB.AppId+"/achievements", Facebook.HttpMethod.GET);
Then to award a player an achievement, it's just this:
var dict = new Dictionary<string,string>();
dict["achievement"] = "<URL_TO ACHIEVEMENT_HERE>";
FB.API(FB.UserId+"/achievements", Facebook.HttpMethod.POST, null, dict);
To get that player's achievment that they completed, it's:
FB.API(FB.UserId+"/achievements", Facebook.HttpMethod.GET);