Start a new topic

Cannot fetch a user

So I have just added two unique users to my backend. I am trying to discover one of the users in my test app but I am not seeing anything. I have added a custom ID to each of the users (ex: user.put("UserID", "123456") and I have updated the server). I can see that both these users exist and that the data has been stored in the backend. I am looping through all the ID's(which includes the ones I have given to the user) and am running the following code:



criteria.set(TAG_USER_ID, iFriend.getId());

Gdx.app.log(TAG, "Friend ID " + iFriend.getId().equals("662493754"));

try {

User[] results = users.lookupBlocking(criteria).execute();

} catch (Exception e) {

Gdx.app.error(TAG, "failed to fetchByFilterCriteria");

}



where iFriend is a GraphUser(the ID's are facebook ID's). The out put I get "failed to fetchByFilterCriteria" , but when I check the id directly via " iFriend.getId().equals("123456")", it returns true. So why am I not finding the user?



**Also, there is no way to edit a post once you send it or to respond to an answer(like comments). Hopefully that will be updated in the future.

> @Edward said:

> Hey,

>

> Every request needs a reference to the active client, and this request is failing because that reference is null. Can you post the code you are using to make the request?

>

> User[] myUsers = myClient.user().retrieveBlocking(...).execute();

>

> should work for this.



Sure. After I get the user, I retrieve the data.



UserDiscovery users = mContext.mKinveyClient.userDiscovery();

User[] results = users.lookupByUserNameBlocking(iUser.getUserName()).execute();

System.out.println("Retrieved data results[0]: " + results[0].retrieveBlocking().execute());



What you posted does work.
Hey,



Every request needs a reference to the active client, and this request is failing because that reference is null. Can you post the code you are using to make the request?



User[] myUsers = myClient.user().retrieveBlocking(...).execute();



should work for this.
> @Edward said:

> Hey,

>

> UserLookup is intended for retrieving information about Users without actually exposing all fields-- Since that's not applicable to your usecase, you can just use the `User.retrieve` methods:

>

> http://devcenter.kinvey.com/android/reference/api/java/reference/com/kinvey/java/User.html#retrieveBlocking(com.kinvey.java.Query)

>

>



Thanks for the help Ed, but I have one final question related to this issue. I am trying to access/retrieve a looked up user's data but I am running into an error:



java.lang.NullPointerException: abstractKinveyClient must not be null

at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:208)

at com.kinvey.java.core.AbstractKinveyClientRequest. (AbstractKinveyClientRequest.java:129)

at com.kinvey.java.core.AbstractKinveyJsonClientRequest. (AbstractKinveyJsonClientRequest.java:45)

at com.kinvey.java.User$Retrieve.(User.java:670)

at com.kinvey.java.User.retrieveBlocking(User.java:388)



I am not sure what would cause this error. The user is not null and I can get its username and id just fine.
Hey,



UserLookup is intended for retrieving information about Users without actually exposing all fields-- Since that's not applicable to your usecase, you can just use the `User.retrieve` methods:



http://devcenter.kinvey.com/android/reference/api/java/reference/com/kinvey/java/User.html#retrieveBlocking(com.kinvey.java.Query)



> @Edward said:

> Hey,

>

> by default, we limit the fields that can be used for userlookup. Take a look here for the full list: http://devcenter.kinvey.com/rest/guides/users#lookup

>

> As a workaround, is it possible to merge the `UserName` field and the `username` field?

>

> If that isn't possible, you can also lower the privacy settings on the User collection so that all fields can be used for lookup. Visit: console.kinvey.com/addons/users

>

> and on the left column, click on `settings`. Then, set `Permissions` to `Full`, and try again.



Ok I can work with the user look up limitation , but I still have an issue with getting the data from another user object. Here is the code I use to get a user:





final UserDiscovery users = KinveyClient.userDiscovery();

final UserLookup criteria = users.userLookup();

User[] results = users.lookupByFacebookIDBlocking(FB_ID).execute();



When I print out the User, I only see these fields: id, username, and social identity. The problem is that I have added more fields with are not visible. I have set permissions to Full and I still see no change. My question is, is it possible for a user to see another users fields (specifically ones that are not on the list you mentioned)?



I can work around this but it is not elegant. I could have every user create a readable file that other users could then read the data off of. I have tested this in another application and it works but in this case it just seems unnecessary.
Hey,



by default, we limit the fields that can be used for userlookup. Take a look here for the full list: http://devcenter.kinvey.com/rest/guides/users#lookup



As a workaround, is it possible to merge the `UserName` field and the `username` field?



If that isn't possible, you can also lower the privacy settings on the User collection so that all fields can be used for lookup. Visit: console.kinvey.com/addons/users



and on the left column, click on `settings`. Then, set `Permissions` to `Full`, and try again.
Yes that worked but it just created more questions. You said this wouldn't work since the fields were not created. See this https://www.dropbox.com/s/rqo1xllbs49afz3/userCP.png . I want to be able to access those fields on any user. "UserName" was a field when I accessed it, but it did not return a result. It seems like only a user id and user name are accessible by other users. Is that correct? Just to outline what I am trying to do. I set a field on a user "userA.put(TEST_FIELD, "userA" );" I update this and now I tell user B to



criteria.put(TEST_FIELD, "userA");

User[] results = KinveyClient.userDiscovery().lookupBlocking(criteria).execute();



This should return one user (userA), but it doesn't. So the root of this question is: If I set a value on a user via 'put', can another user access that value?



Here is my output using "UserName":



Jan 16, 2014 10:49:46 AM com.google.api.client.http.HttpRequest execute

CONFIG: -------------- REQUEST --------------

POST https://baas.kinvey.com/user/kid_VVohczrlXM/_lookup

Accept-Encoding: gzip

Authorization:

Content-Type: application/json; charset=UTF-8

User-Agent: android-kinvey-http/2.6.12

x-kinvey-api-version: 3

x-kinvey-device-information: JAVA/1.7.0_45

Content-Type: application/json; charset=UTF-8

Content-Length: 18



Jan 16, 2014 10:49:46 AM com.google.api.client.http.HttpRequest execute

CONFIG: curl -v --compressed -X POST -H 'Accept-Encoding: gzip' -H 'Authorization: ' -H 'Content-Type: application/json; charset=UTF-8' -H 'User-Agent: android-kinvey-http/2.6.12' -H 'x-kinvey-api-version: 3' -H 'x-kinvey-device-information: JAVA/1.7.0_45' -H 'Content-Type: application/json; charset=UTF-8' -d '@-' -- 'https://baas.kinvey.com/user/kid_VVohczrlXM/_lookup'
Jan 16, 2014 10:49:46 AM com.google.api.client.util.LoggingByteArrayOutputStream close

CONFIG: Total: 18 bytes

Jan 16, 2014 10:49:46 AM com.google.api.client.util.LoggingByteArrayOutputStream close

CONFIG: {"UserName":"sha"}

Jan 16, 2014 10:49:46 AM com.google.api.client.http.HttpResponse

CONFIG: -------------- RESPONSE --------------

HTTP/1.1 400 Bad Request

X-Kinvey-Request-Id: 1f8b8d2d1ac946d4a157c86af2ce515a

X-Kinvey-API-Version: 3

Date: Thu, 16 Jan 2014 17:49:46 GMT

Content-Length: 162

Connection: keep-alive

Content-Type: application/json; charset=utf-8

X-Powered-By: Express

Server: nginx



Jan 16, 2014 10:49:46 AM com.google.api.client.util.LoggingByteArrayOutputStream close

CONFIG: Total: 162 bytes

Jan 16, 2014 10:49:46 AM com.google.api.client.util.LoggingByteArrayOutputStream close

CONFIG: {"error":"InvalidQuerySyntax","description":"The query string in the request has an invalid syntax","debug":"not allowed to invoke _lookup on attribute UserName"}



Hey,



Can you try changing the value of TAG_USER_ID to be `username` instead of `userName`? This error usually occurs because the criteria doesn't exist as a field name, so that might be the issue.
Hey Ed,



Here is the full error:



Jan 07, 2014 8:54:45 PM com.google.api.client.http.HttpRequest execute

CONFIG: -------------- REQUEST --------------

POST https://baas.kinvey.com/user/kid_VVohczrlXM/_lookup

Accept-Encoding: gzip

Authorization:

Content-Type: application/json; charset=UTF-8

User-Agent: android-kinvey-http/2.6.11

x-kinvey-api-version: 3

x-kinvey-device-information: JAVA/1.7.0_45

Content-Type: application/json; charset=UTF-8

Content-Length: 18



Jan 07, 2014 8:54:45 PM com.google.api.client.http.HttpRequest execute

CONFIG: curl -v --compressed -X POST -H 'Accept-Encoding: gzip' -H 'Authorization: ' -H 'Content-Type: application/json; charset=UTF-8' -H 'User-Agent: android-kinvey-http/2.6.11' -H 'x-kinvey-api-version: 3' -H 'x-kinvey-device-information: JAVA/1.7.0_45' -H 'Content-Type: application/json; charset=UTF-8' -d '@-' -- 'https://baas.kinvey.com/user/kid_VVohczrlXM/_lookup'
Jan 07, 2014 8:54:45 PM com.google.api.client.util.LoggingByteArrayOutputStream close

CONFIG: Total: 18 bytes

Jan 07, 2014 8:54:45 PM com.google.api.client.util.LoggingByteArrayOutputStream close

CONFIG: {"UserName":"sha"}

Jan 07, 2014 8:54:45 PM com.google.api.client.http.HttpResponse

CONFIG: -------------- RESPONSE --------------

HTTP/1.1 400 Bad Request

X-Kinvey-Request-Id: 203ce3c2d8e449feadf3eae8b1c76bf8

X-Kinvey-API-Version: 3

Date: Wed, 08 Jan 2014 03:54:45 GMT

Content-Length: 162

Connection: keep-alive

Content-Type: application/json; charset=utf-8

X-Powered-By: Express

Server: nginx



Jan 07, 2014 8:54:45 PM com.google.api.client.util.LoggingByteArrayOutputStream close

CONFIG: Total: 162 bytes

Jan 07, 2014 8:54:45 PM com.google.api.client.util.LoggingByteArrayOutputStream close

CONFIG: {"error":"InvalidQuerySyntax","description":"The query string in the request has an invalid syntax","debug":"not allowed to invoke _lookup on attribute UserName"}

SceneSwitchLoadSequence: failed to fetchByFilterCriteria



This when I try to search for the users username that I set via "user.put(UserName, "Name") [update included]." I know that the user exists and that the user name is correct because I can see it in the backend.



Hey, thanks for your patience!



Can you enable debug logging for the java library? http://devcenter.kinvey.com/java/guides/troubleshooting



This will dump the request and response json to the logs, which will help me figure out where the issue might be.



@Caroline Thanks for letting me know.
Sorry about the delay in response on the Kinvey side, our lead Java engineer is away on vacation and expected back next week.
I tried changing "criteria.set(TAG_USER_ID, iFriend.getId());" to "criteria.put(TAG_USER_ID, iFriend.getId());" but I am still getting an error:



com.kinvey.java.core.KinveyJsonResponseException: InvalidQuerySyntax The query string in the request has an invalid syntax
I completely forgot to post the error:

com.kinvey.java.core.KinveyJsonResponseException: InvalidQuerySyntax

The query string in the request has an invalid syntax



Not sure why I would get that since I followed the docs procedure.
But again, that doesn't make sense. Since it says "User Discovery allows an app to respect user privacy but enable user discovery at the same time." This makes it sound like user discovery is a way around the privacy issues.
Login or Signup to post a comment