Kann ich nach 15 Sekunden einen Facebook -API -Anruf in Einheit beenden?
Posted: 14 Apr 2025, 00:19
Ich habe den folgenden Code: < /p>
In diesem Code nenne ich die Facebook -API mit der Abfrage "Me/Friends" , um die Facebook -IDs der Freunde des Spielers zu erhalten, die auch das fragliche Spiel spielen. Gibt es eine Möglichkeit, die Zeit zu begrenzen, die Facebook benötigt, um die Abfrage zurückzugeben? Ich möchte es absagen, wenn es mehr als 15 Sekunden dauert. Ich möchte die Abfrage nicht wirklich ignorieren und alles andere um sie herum fordern>
Code: Select all
//get the Player's friends' IDs (friends who have also played this game)
public void GetIDsOfFriends(Action OnComplete, Action NoInternet)
{
//if the Player's friends' ID have already been retrieved from Facebook
if (Score.friendIDs.Count > 0)
{
OnComplete();
return;
}
string query = "me/friends";
FB.API(query, HttpMethod.GET, result =>
{
var dictionary = new Dictionary();
Debug.Log("fb api working");
try
{
Debug.Log("trying to read dictionary");
dictionary = (Dictionary)Facebook.MiniJSON.Json.Deserialize(result.RawResult);
}
catch (OverflowException)
{
NoInternet();
return;
}
Debug.Log("raw result: " + result.RawResult);
var friendsList = (List)dictionary["data"];
foreach (var dict in friendsList)
{
var friendName = ((Dictionary)dict)["name"].ToString();
//print the friend name in the log
Debug.Log("friend name: " + friendName);
var friendId = ((Dictionary)dict)["id"].ToString();
Debug.Log("friend ID: " + friendId);
//add the ID to the Score class
Score.friendIDs.Add(friendId);
}
//execute OnComplete once all the friends' IDs are in the Score.friendsIDs variable
OnComplete();
});
}