can't load scores from leaderboard - c#

i'm setting up a leaderboard system in my unity game, using the google play games services plugin.
i want to load score in order to integrate them in my custom LeaderbordUI,
I followed the documentation and used the ILeaderboard.LoadScores but it's not working.
when i check the logcat i get this :
02-04 11:03:56.580: W/Unity(18969): !!! [Play Games Plugin DLL] 02/04/19 11:03:56 +01:00 WARNING: Error returned from fetch: -108
I have tried to loadScore with the method "Social.LoadScores" and "PlayGamesPlatform.Instance.LoadScores", but i'm getting the same warning.
PS: when i use Social.ShowLeaderboardUI() it shows me the leaderboard.
but when i use PlayGamesPlatform.Instance.ShowLeaderboardUI(LB_Stars.id) to show a specific leaderboard it gives me "hmm,something went wrong in play games"
public void LoadLeaderboard()
{
LB_Stars.LoadScores(ok =>
{
if (ok)
{
LoadUsersAndDisplay(LB_Stars);
}
else
{
Debug.Log("Error retrieving STARS leaderboard");
}
});
}
internal void LoadUsersAndDisplay(ILeaderboard lbStar)
{
Debug.Log("gonna load user and display them");
List<string> userIds = new List<string>();
foreach (IScore score in lbStar.scores)
{
userIds.Add(score.userID);
}
Social.LoadUsers(userIds.ToArray(), (users) =>
{
string status = "Leaderboard loading: " + lbStar.title + " count = " +
lbStar.scores.Length;
foreach (IScore score in lbStar.scores)
{
IUserProfile user = FindUser(users, score.userID);
if (user != null)
{
UserLeaderboardClone = Instantiate(UserLeaderboardPrefab);
UserLeaderboardClone.name = score.rank.ToString();
LeaderboardUserScript lbUser = UserLeaderboardClone.GetComponent<LeaderboardUserScript>();
lbUser.transform.SetParent(LBScrollview.content.transform, false);
FillUserInfo(lbUser, user, score);
}
}
});
}

Okay i've figured it out, based on a comment on github https://github.com/playgameservices/play-games-plugin-for-unity/issues/2045#issuecomment-350335234

After spending a couple of hours on this, my problem turned out to be my game was using leaderboard ids from another app.
So it failed with this "unauthorized error", however the exact cause was not given.
The reason why it happened was because the play games configuration in unity was caching old values. When you open it - it has the correct ids, however in the generated GPGSids.cs file - wrong ids are present.
The solution was simply to regenerate that by re-saving the configuration.

Related

How to point to the correct Store in Outlook automation by C#?

I have a lot of VBA automation that interlinks an Outlook and Word solution; it is fine, but time is inexorable... so, I'm start to decorating and extending that old solution, wraping it with C#/VS2017.
Through a conventional Winform I can choose my patients, and from this action I do a lot of actions, including open the correct Outlook contact; that's the problem, because I can't get the correct Store; the patients.pst, depending on the machine, may be the 1st, 2nd, 3rd...
In VBA I do this:
WhichStoreNameToPointAt="patients"
Set myNamespace = myolApp.GetNamespace("MAPI")
For i = 1 To myNamespace.Stores.Count Step 1
If myNamespace.Stores.item(i).DisplayName = WhichStoreNameToPointAt Then
intOutlookItemStore = i
End if
End If
Set myFolderPatients = myNamespace.Stores.item(intOutlookItemStore).GetDefaultFolder(olFolderContacts)
And it always functions like a charm.
In C# I tried a lot of variations, and could not point to the correct store:
public void OpenPatientContact(string patientName)
{
Outlook.Store whichStore = null;
Outlook.NameSpace nameSpace = OlkApp.Session;
int i = 1;
foreach (Outlook.Folder folder in nameSpace.Folders)
{
bool p = false;
if (whichStoreNameToPointAt == folder.Name)
{
p = true;
whichStore = folder.Store;
//Correct Store selected; I can tell because of this watch:
//whichStore.displayname == whichStoreNameToPointAt
}
i++;
if (p)
break;
}
var contactItemsOlk = whichStore.Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderContacts).Items;
// The problem is below; always the first Store
Outlook.ContactItem contact = (Outlook.ContactItem)contactItemsOlk
.Find(string.Format("[FullName]='{0}'", patientName)); //[1];
if (contact != null)
{
contact.Display(true);
}
else
{
MessageBox.Show("The contact information was not found.");
}
}
Unfortunately, it keeps pointing ever to the same first Store, the one that has no patients...
If I change the Store order I can get past this and test other stuff, but of course it is not the right way.
Any other heads/eyes to see the light?
TIA
While seated writing the question, looking at a yellow rubber duck - and a lot of other stuff that belongs to my 1 yo daughter ;), I realized that whichStore.Session.GetDefaultFolder is a little strange in this context. I only changed this
var contactItemsOlk = whichStore.Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderContacts).Items;
To that:
var contactItemsOlk = whichStore.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderContacts).Items;
Voilá! Magic happens with C# too!
Session returns the default NameSpace object for the current session.
PS: yellow rubber duck; guys of The Pragmatic Programmer really knows some secrets and tricks ;)
Thanks Thomas and Hunt!

xamarin form cannot keep last state

I am trying to keep the state of some variable of my xamarin form when I close the app and start it but is not working
I have 2 variable "isconnected" and "eric"
var app = App.Current;
app.Properties["UserIsConnected"] = true;
app.Properties["userName"] = "eric";
await app.SavePropertiesAsync();
After closing the app when I restart it and trying to get the values of my variable like this :
((bool)App.Current.Properties["UserIsConnected"] ))
((string)App.Current.Properties["userName"] ))
I have this error:
System.Collections.Generic.KeyNotFoundException: The given key 'UserIsConnected' was not present in the dictionary.
How can I saved my variable and get them when restart the app?
thanks in advance for your help
You need to check if the value is exist before we get the value of it. You can do it like this:
private async Task saveDataAsync() {
if (App.Current.Properties.ContainsKey("UserIsConnected"))
{
//Do something awesome.
bool UserIsConnected = ((bool)App.Current.Properties["UserIsConnected"]);
string name = ((string)App.Current.Properties["userName"]);
System.Diagnostics.Debug.WriteLine("UserIsConnected= " + UserIsConnected +" name =" + name);
}
else {
var app = App.Current;
app.Properties["UserIsConnected"] = true;
app.Properties["userName"] = "eric";
await app.SavePropertiesAsync();
}
}
You seem to be saving a property with the key "isconnected" and trying to retrieve it with a different key ("UserIsConnected").
EDIT:
OK, thanks for clearing that the error I pointed out was a typo. As for the problem, try this instead:
App.Current.Properties.Add("UserIsConnected", true);
await App.Current.SavePropertiesAsync();
And make sure you check if the key exists before using it:
if (App.Current.Properties.ContainsKey("UserIsConnected"))
{
//Do something awesome.
}

C# Ebay API ReviseFixedPriceItemCall Description Not Updating

So we all know the eBay active content change is coming up here soon. I'm trying to update my listing descriptions to remove the active content. My calls are not failing, but they do not seem to be updating the description. I've tried ReviseFixedPriceItemCall and ReviseItemCall with no success. I've tried changing the options of the DescriptionReviseMode with no success. Any help would be appreciated. This is what I currently have that is going through without any errors, but does not update the description. Thanks in advance.
var reviseFp = new ReviseFixedPriceItemCall(oContext2);
//var reviseFp = new ReviseItemCall(oContext2);
var item = new ItemType { ItemID = myId, Description = newDescription };
item.DescriptionReviseModeSpecified = true;
item.DescriptionReviseMode = DescriptionReviseModeCodeType.Replace;
reviseFp.Item = item;
try
{
reviseFp.Execute();
}
catch (Exception ex)
{
Console.WriteLine(myId + " : " + ex.ToString());
}
So it turns out that this code works perfectly fine. I was trying to have the javascript removed for the active content changed, but it was never being removed. Well just manually going and editing the listing from eBay itself would not remove the javascript either. So it wasn't the code at all it was the listing. I got on the horn with eBay support and they couldn't remove it either.

Not getting correct data from span

I've been making a custom user handler for Jessecar's SteamBot, which is unrelated to the problem I'm having, but essentially what I've done, is I've made it so you can set the bot to play a specific game by App ID, and I've been using this to idle on games for Steam Trading Cards, the only issue is, the only way I can check if it's finished, is by checking its inventory and how many cards are supposed to drop, which isn't too much of a hassle, but the main reason I created this was for efficiency, and doing this every time kind of defeats the purpose of it.
Because of this, I tried getting data from the badge page for the bot on the game that it's playing, this is what I have so far...
else if (message.StartsWith(".updateidle"))
{
var webGet = new HtmlWeb();
var SteamID64 = Bot.SteamClient.SteamID.ConvertToUInt64();
string htmlget = "http://www.steamcommunity.com/profiles/" + SteamID64 + "/gamecards/" + newgame;
var doc = webGet.Load(htmlget);
HtmlNode hoursNode = doc.DocumentNode.SelectSingleNode("//div[#class=\"badge_title_stats_playtime\"]");
string hours = Regex.Match(hoursNode.InnerText, #"[0-9\.,]+").Value;
var cards = doc.DocumentNode.SelectSingleNode("div[#class='badge_title_stats_drops']/span").InnerText;
if (hours == string.Empty)
{
hours = "0.0";
}
Bot.SteamFriends.SendChatMessage(OtherSID, type, "I have been idling for " + hours + " hours on game " + newgame + " and have " + cards + " card drops remaining.");
}
Getting the hours works fine, if the bot has no time on that game, it doesn't appear, so I just check if it's empty then set it to 0.0, however, with the cards, it appears as either "No card drops remaining" or " card drops remaining" which it doesn't get either, I tried using the same method as the hours and only get it if it's a number, and it still returns with "0", same result goes for this...
I also tried again with doing a check if the string is empty, because that could mean there is no card drops remaining, as there would be no numbers, and I also had a look online for methods of getting span data inside a div, or span data general, and neither methods worked, they'd just return with "0". And if you can't already tell, I do have the HTML Agility Pack.
So building in my previous answer, that I have decided not to edit, since the followup here is gonna be large. I amusing both Selenium and Html Agility Pack for this. First I log in using Selenium(I am using Mono btw). After that I type in authorize my pc manually(if yours is already authorized then skip this step) and then go to the console and press any key to proceed with getting card info. I will gather the card info for all games in this case. I can't identify which game still has card drops as it has not been implemented yet.
class MainClass
{
public static void Main(string[] args)
{
string userName = "username";
string password ="password";
string steamProfile = "steamprofile";
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
using (var driver = new FirefoxDriver())
{
// Go to the home page
driver.Navigate().GoToUrl("https://store.steampowered.com//login/?redir=0");
// Get the page elements
var userNameField = driver.FindElementById("input_username");
var userPasswordField = driver.FindElementById("input_password");
//var loginButton = driver.FindElementById("login_btn_signin");
var loginButton = driver.FindElementByXPath("//button[#class='btnv6_blue_hoverfade btn_medium']");
// Type user name and password
userNameField.SendKeys(userName);
userPasswordField.SendKeys(password);
// and click the login button
loginButton.Click();
System.Threading.Thread.Sleep(5000);
//Type authorization code and enter manually.
System.Console.ReadKey();
driver.Navigate().GoToUrl("http://steamcommunity.com/profiles/"+steamProfile+"/badges");
driver.GetScreenshot().SaveAsFile(#"screen.png", ImageFormat.Png); //Debuggin purposes, as I was first using PhantomJS
htmlDoc.LoadHtml(driver.PageSource);
Console.Clear();
}
HtmlNodeCollection col = htmlDoc.DocumentNode.SelectNodes("//span[#class='progress_info_bold']");
foreach (HtmlNode n in col)
{
Console.WriteLine(n.InnerText);
}
}
}
}
The output in my case
5 of 29 tasks completed
No card drops remaining
No card drops remaining
No card drops remaining
4 card drops remaining
3 card drops remaining
This code also gives you the badge progress. You must figure out yourself how to filter your data in Html Agility Pack(read up on xpath). I also recommend that you use Selenium, since you can start a steamgame from your webpage using it.
remember that the xpath I gave you in my first answer and is also used in the code above finds ALL("//") the that has a class that equals "progress_info_bold".
You need to be more specific about what nodes to pick. I highly disencourage you from ever using regex to try and navigate the innertext or innerhtml of an htmldocument.
To find the HTmlNodes regarding if there is anymore cards to drop. try using this xpath:
"//span[#class='progress_info_bold']"
These nodes will either contain the text:
"No card drops remaining"
or
number+" card drops remaining"

Big websites not loading at all - error

I have created a web browser for windows phone 7. In that am saving the history of browsing also with title of that page. But due to this codes when i tried to load a somewhat big website like thinkdigit,etc. are not loading. At the same time if i delete that particular codes then no history is being recorded in the history page. It shows error for the below highlighted code - "An unknown error has occurred. Error: 80020006". I think its due to big site or else do i need to put milliseconds or what i have to do???
Thanks in advance for your hard work!!!
Below is the codes i have used for it-
private void browsers_Navigated(object sender,System.Windows.Navigation.NavigationEventArgs e)
{
pbarWebClient.Visibility = System.Windows.Visibility.Collapsed;
if (!fromHistory)
{
if (HistoryStack_Index < HistoryStack.Count)
{
HistoryStack.RemoveRange(HistoryStack_Index, HistoryStack.Count - HistoryStack_Index);
}
HistoryStack.Add(e.Uri);
if (!app.incognito)
{
********string title = (string)browsers[this.currentIndex].InvokeScript("eval", "document.title.toString()");********----->This is the error.
stream.WriteLine(title + ";" + e.Uri.ToString());
}
HistoryStack_Index += 1;
}
fromHistory = false;
navigationcancelled = false;
Stop.Visibility = Visibility.Collapsed;
}
I would expect that eval has been overridden or in some other way suppressed on the site(s) in question.
"80020006" is a javascript invocation error code. Simply assuming that a javascript method will be available and work in the same way on any site is not always going to be true.
Finally i got the suitable answer for my own question. Just replace the above codes with this-
if (!app.incognito)
{
Thread.Sleep(100);
Dispatcher.BeginInvoke(() =>
{
string title = (string)browsers[this.currentIndex].InvokeScript("eval", "document.title.toString()");
stream.WriteLine(title + ";" + e.Uri.ToString());
});
}

Categories