void handleJSONFile(FriendsIds _friendsIds, FriendUsers _friendUsers) { bool userExisted = true; if (!File.Exists(userJSONFilePath)) { //create a new JSON file to edit and write the basic structure to it. string starterJSONText = "{\"ids\": {}, \"users\": {}, \"lastAccess\": {}}"; byte[] starterJSONByteArray = System.Text.Encoding.ASCII.GetBytes(starterJSONText); logHandler.writeToLog("creating new file: " + userJSONFilePath, Color.green); File.WriteAllBytes(userJSONFilePath, starterJSONByteArray); userExisted = false; } string dataAsJson = File.ReadAllText(userJSONFilePath); GameUserJSON _gameUserJSON = JsonUtility.FromJson <GameUserJSON>(dataAsJson); _gameUserJSON.ids = _friendsIds; _gameUserJSON.users = _friendUsers; if (!userExisted) { _gameUserJSON.lastAccess = System.DateTime.Now.ToString(); } currentGameUserJSON = _gameUserJSON; GetComponent <GameStateHandler>().player.GetComponent <Player>().gameUserJSON = currentGameUserJSON; GetComponent <GameStateHandler>().player.GetComponent <Player>().followerCount = _friendsIds.ids.Count; dataAsJson = JsonUtility.ToJson(_gameUserJSON); File.WriteAllText(userJSONFilePath, dataAsJson); GetComponent <JSONEnemyHandler>().loadJSONDataToEnemies(currentGameUserJSON); //write back to the file path the modified gameUserJSON }
void getFollowerIdsCallback(bool success, string response) { if (success) { friendsIds = JsonUtility.FromJson <FriendsIds>(response); logHandler.writeToLog("SUCCESS: " + friendsIds.ids.Count + " FOLLOWER IDS were fetched", Color.green); //once you have all of the ids you can pass them into another API call for users lookup Dictionary <string, string> parameters = new Dictionary <string, string>(); string followersIdsString = string.Join(", ", friendsIds.ids.ToArray()); parameters["user_id"] = followersIdsString; StartCoroutine(Twity.Client.Get("users/lookup", parameters, getFollowerUsersCallback)); } else { print("ERROR: " + response); logHandler.writeToLog("ERROR: " + response, Color.red); } }