I am trying to get name
from logged In user Session and display it on a textview from the following code snippet.
private void getUserName(){
client = new Client(requireActivity())
.setEndpoint(endpoint)
.setProject(project);
account = new Account(client);
account.getSession("current",
new CoroutineCallback<>((result, error)-> {
if (error != null) {
error.printStackTrace();
}else{
// pass `result` in to a json object
try {
JSONObject jsonObject = new JSONObject(String.valueOf(result));
//get parameter "name" from the json object
String name = jsonObject.getString("name");
// pass the name parameter into textview
binding.userNameDisplay.setText(name);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
));
}
I get this exception Error
org.json.JSONException: Value Session(id of type java.lang.String cannot be converted to JSONObject
can you log the result
to check its shape
which lang is that?
Java. I did the log. Its is not in JSON. Weird stuff. they is no name feild. But i can see the user name on the appwrite console. All i can see on the log is id
createdAt
etc
can you show me the output
android sdk?
JSON Error syc...scan E The result string is not a valid JSON object: Session(id=643664af54b3546543bf, createdAt=2023-04-12T07:58:39.350+00:00, userId=643612e4b8d495e5f32a, expire=2024-04-11 07:58:39.350, provider=email, providerUid=********, providerAccessToken=, providerAccessTokenExpiry=, providerRefreshToken=, ip=********, osCode=AND, osName=Android, osVersion=12, clientType=browser, clientCode=AN, clientName=Android Browser, clientVersion=, clientEngine=WebKit, clientEngineVersion=, deviceName=smartphone, deviceBrand=Samsung, deviceModel=SM-A136B, countryCode=--, countryName=Unknown, current=true)
noo, just the result before parsing it
Session(id=643674b62e1330fa1564, createdAt=2023-04-12T09:07:02.501+00:00, userId=Sam, expire=2024-04-11 09:07:02.501, provider=email, providerUid=*****************, providerAccessToken=, providerAccessTokenExpiry=, providerRefreshToken=, ip=************, osCode=AND, osName=Android, osVersion=12, clientType=browser, clientCode=AN, clientName=Android Browser, clientVersion=, clientEngine=WebKit, clientEngineVersion=, deviceName=smartphone, deviceBrand=Samsung, deviceModel=SM-A136B, countryCode=--, countryName=Unknown, current=true)
Its still same log
there's a toString()
method for the result object according to this can you try that
https://appwrite.io/docs/client/account?sdk=android-java#accountGetSession
Recommended threads
- custom domain with CloudFlare
Hi all, it seems that CloudFlare has blocked cross-domain CNAME link which made my app hostname which is in CloudFlare, unable to create a CNAME pointing to clo...
- My organization's project is blocked
My organization's project is blocked so unblocked my organization then I will this
- Can't Create An Account with Gmail Domai...
Hi, when using account.create() to register a new user with the Gmail domain, I got "There was an error processing your request. Please check the inputs and try...