Most of the time developers have a question, “how can we make user profile more interactive so that user can save his additional information along with user creation” ? App42 Cloud API provides a feature which helps the user to save additional data along with user creation to make his profile more effective.
多くの時間、開発者は次のような疑問を持っています。「ユーザーがユーザー作成に沿って、追加的な情報を保存するために、ユーザープロファイルをよりインタラクティブにするにはどうすればいいのか?」App42 Cloud API は、ユーザーがプロファイルをよりインタラクティブにするために、ユーザー作成に沿って追加的なデータを保存するのに役立つ機能を提供します。
With the help of this feature, developers can add their user information to make quality apps. Let us take an example where we save additional information of a user, which contains his achievement details.
Put forth is the code snippet that will save additional information along with the user creation.
String userName = "Ricky" ; String email ="ricky.ponting@gmail.com";
JSONObject profile = new JSONObject();
profile.put("firstName", "Ricky");
profile.put("lastName", "Ponting");
profile.put("AllAchievements", 200);
profile.put("ManOfTheSeries", 80);
profile.put("ManOfTheMatch", 120);
App42API.setDbName("Your db Name");
userService.addJSONObject("Your Collection Name", profile);
User user = userService.createUser(userName, "password", email);
System.out.println("UserName is : " + user.getUserName());
JSONObject profileObject = new JSONObject(user.getJsonDocList().get(0).getJsonDoc());
System.out.println("FirstName is : " + profileObject.getString("firstName"));
System.out.println("LastName is : " + profileObject.getString("lastName"));
System.out.println("All Achievements : " +profileObject.getString("AllAchievements"));
If the user is already created, use the code snippet given below to add the additional information.
String userName = "Ricky";
JSONObject profileJSON = new JSONObject();
profileJSON.put("firstName", "Ricky");
profileJSON.put("lastName", "Ponting");
profileJSON.put("AllAchievements", 200);
profileJSON.put("ManOfTheSeries", 80);
profileJSON.put("ManOfTheMatch", 120);
App42API.setDbName("test");
userService.addJSONObject("UserCollection", profileJSON);
User getObj = userService.getUser(userName);
User user = userService.createOrUpdateProfile(getObj);
System.out.println("UserName is : " + user.getUserName());
JSONObject profileObject = new JSONObject(user.getJsonDocList().get(0).getJsonDoc());
System.out.println("FirstName is : " + profileObject.getString("firstName"));
System.out.println("LastName is : " + profileObject.getString("lastName"));
System.out.println("All Achievements : " +profileObject.getString("AllAchievements"));
Fetch/Update Additional Data of User: With the above code snippet, you will get the object Id of the information, which you have saved in App42 Database. Using this object id, you can find the information from App42 Database using No-SQL Storage Service. This has been stated below.
String dbName ="Your db Name" ;
String collectionName = "Your Collection Name";
String objectId = "Object Id";
StorageService storageService = App42API.buildStorageService();
Storage storage = storageService.findDocumentById(dbName, collectionName,objectId);
JSONObject profileObject = new JSONObject(storage.getJsonDocList().get(0).getJsonDoc());
System.out.println("FirstName is : " + profileObject.getString("firstName"));
System.out.println("LastName is : " + profileObject.getString("lastName"));
System.out.println("All Achievements : " +profileObject.getString("AllAchievements"));
As well as you can add or update the profile using the below code snippet:
String dbName ="Your db Name" ;
String collectionName = "Your Collection Name";
String objectId = "Object Id";
JSONObject keysUpdate = new JSONObject();
keysUpdate.put("AllAchievements", 205);
StorageService storageService = App42API.buildStorageService();
Storage storage = storageService.addOrUpdateKeys(dbName, collectionName,objectId,keysUpdate);
JSONObject profileObject = new JSONObject(storage.getJsonDocList().get(0).getJsonDoc());
System.out.println("FirstName is : " + profileObject.getString("firstName"));
System.out.println("LastName is : " + profileObject.getString("lastName"));
System.out.println("All Achievements : " +profileObject.getString("AllAchievements"));
System.out.println("Man Of The Series : " +profileObject.getString("ManOfTheSeries"));
If you have queries or need further assistance to integrate this feature in your App, please feel free to reach us at our Forum.
この機能の助けによって、開発者は質の高いアプリを作るために、ユーザー情報を追加できます。1つ例を挙げてみましょう。そこでは、私達はユーザーの追加的な情報を保存できます。その情報は成果の詳細を含みます。
下記にコードスニペットがあり、ユーザー作成に沿って追加的な情報を保存しましょう。
String userName = "Ricky" ; String email ="ricky.ponting@gmail.com";
JSONObject profile = new JSONObject();
profile.put("firstName", "Ricky");
profile.put("lastName", "Ponting");
profile.put("AllAchievements", 200);
profile.put("ManOfTheSeries", 80);
profile.put("ManOfTheMatch", 120);
App42API.setDbName("Your db Name");
userService.addJSONObject("Your Collection Name", profile);
User user = userService.createUser(userName, "password", email);
System.out.println("UserName is : " + user.getUserName());
JSONObject profileObject = new JSONObject(user.getJsonDocList().get(0).getJsonDoc());
System.out.println("FirstName is : " + profileObject.getString("firstName"));
System.out.println("LastName is : " + profileObject.getString("lastName"));
System.out.println("All Achievements : " +profileObject.getString("AllAchievements"));
もしユーザーが既に作られているならば、追加的な情報を追加するために下記に与えられているコードスニペットを使用しましょう。
String userName = "Ricky";
JSONObject profileJSON = new JSONObject();
profileJSON.put("firstName", "Ricky");
profileJSON.put("lastName", "Ponting");
profileJSON.put("AllAchievements", 200);
profileJSON.put("ManOfTheSeries", 80);
profileJSON.put("ManOfTheMatch", 120);
App42API.setDbName("test");
userService.addJSONObject("UserCollection", profileJSON);
User getObj = userService.getUser(userName);
User user = userService.createOrUpdateProfile(getObj);
System.out.println("UserName is : " + user.getUserName());
JSONObject profileObject = new JSONObject(user.getJsonDocList().get(0).getJsonDoc());
System.out.println("FirstName is : " + profileObject.getString("firstName"));
System.out.println("LastName is : " + profileObject.getString("lastName"));
System.out.println("All Achievements : " +profileObject.getString("AllAchievements"));
ユーザーの追加データをフェッチ/アップデート;上記のコードスニペットによって、あなたは情報に関するオブジェクトIDを手に入れるでしょう。それはApp42データベースに保存されています。このオブジェクトIDを使用して、No-SQLストレージサービスを使用しているApp42データベースから、情報を見つけることができます。
String dbName ="Your db Name" ;
String collectionName = "Your Collection Name";
String objectId = "Object Id";
StorageService storageService = App42API.buildStorageService();
Storage storage = storageService.findDocumentById(dbName, collectionName,objectId);
JSONObject profileObject = new JSONObject(storage.getJsonDocList().get(0).getJsonDoc());
System.out.println("FirstName is : " + profileObject.getString("firstName"));
System.out.println("LastName is : " + profileObject.getString("lastName"));
System.out.println("All Achievements : " +profileObject.getString("AllAchievements"));
下記のコードスニペットを使用して、プロファイルを追加したりアップデートしたりできます。
String dbName ="Your db Name" ;
String collectionName = "Your Collection Name";
String objectId = "Object Id";
JSONObject keysUpdate = new JSONObject();
keysUpdate.put("AllAchievements", 205);
StorageService storageService = App42API.buildStorageService();
Storage storage = storageService.addOrUpdateKeys(dbName, collectionName,objectId,keysUpdate);
JSONObject profileObject = new JSONObject(storage.getJsonDocList().get(0).getJsonDoc());
System.out.println("FirstName is : " + profileObject.getString("firstName"));
System.out.println("LastName is : " + profileObject.getString("lastName"));
System.out.println("All Achievements : " +profileObject.getString("AllAchievements"));
System.out.println("Man Of The Series : " +profileObject.getString("ManOfTheSeries"));
もしあなたが質問を持っている、またはアプリにこの機能を統合するためにさらに手助けを必要とするならば、フォーラムで私達にご自由に連絡ください。
Leave A Reply