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.

If this is client side code, you can't fetch a user other than yourself. You would need a custom endpoint on the server that does the query for you on the server and returns back the data you need.
@Daniel: That seems contrary to what the Java guide(http://devcenter.kinvey.com/java/guides/users#lookup) says: "Often times, apps need to share data between users or provide contact information of other users of the app. In such cases, user discovery is a way for your app to retrieve users from the user collection through a query or by fetching all." Also, I have been able to fetch other users using "lookupByFacebookIDBlocking."
The docs are a bit confusing. But if you keep reading they specify certain attributes you can query against. All of the API's use the same REST API, but if you look at the backbone.js docs, they provide a bit more clarity on the privacy policy. (http://devcenter.kinvey.com/backbone/guides/users#lookup)
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.
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.
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
Sorry about the delay in response on the Kinvey side, our lead Java engineer is away on vacation and expected back next week.
@Caroline Thanks for letting me know.
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.



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,



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.
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,



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.
> @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.
Login or Signup to post a comment