Facebook FQL: uid of friends - java

I'm using restfb 1.6.5 (the same problem in 1.6.4) and have problems getting the uids of my friends. This works fine (me-query):
User fbUserMe = fbClient.fetchObject("me", com.restfb.types.User.class);
logger.debug(fbUserMe.getId());
The response body contains something like: {"id":"1234","name":"ME" ...} and fbUserMe.getId() returns my uid. With the next code snipped I want to get the uids of my friends (friends-query):
StringBuffer sb = new StringBuffer();
sb.append("SELECT uid, first_name, last_name FROM user");
sb.append(" WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())");
List<User> users = fbClient.executeQuery(sb.toString(), User.class);
for(User fbUser : users)
{
logger.debug(fbUser.getId());
}
But this always outputs null, although the response body contains this: [{"uid":5678,"first_name":"Peter" ...} ...].
The obvious difference in the response by is id=1234 for the me-query and uid=5678 for the friends-query. If I use a custom class FqlUser like described in RestFB I'm able to get the uid. Now I'm uncertain of the uid. Do I really get same same id (the same my friend would get in a me-Query) or do I get something like the third_party_id described in Facebook: FQL-user?

You're getting the uid. The same id your friend would get in a "me query".

Related

How to get Display Name of Contact by User ID in Applozic?

I am using Digits by Twitter alongside Applozic SDK. I am creating a custom contact list, by using Find Friends provided by Digits, and then using their friends' IDs to get their display name from Applozic.
This my code:
Log.e("Friend ID", user.idStr);
AppContactService appContactService = new AppContactService(context);
Contact contact = appContactService.getContactById(user.idStr);
Log.e("Friend Display Name", contact.getDisplayName());
This is my logcat output:
E/Friend ID: 753958303214870528
E/Friend Display Name: 753958303214870528
E/Friend ID: 751769088456790016
E/Friend Display Name: 751769088456790016
As you can see, even getDisplayName() returns UserID. This is my Applozic Dashboard
.
Is there anything I am doing wrong??
For this you need to make server call and get the User details from server. The above method which your are using it will only check from local data base
You can user this method to get the details from server
Set<String> userIds = new HashSet<>();
userIds.add("user1");
userIds.add("user2");
userIds.add("user3");
UserService.getInstance(context).processUserDetails(userIds); //server call
AppContactService appContactService = new AppContactService(context);
Contact contact = appContactService.getContactById("user1");
if(contact != null){
Log.e("Friend Display Name", contact.getDisplayName());
}

Cannot get user details from post in restfb using java

Recently I've been struggling with getting user information from post_id with java. I'm new in restfb, but after reasearching, below code should work. All available permissions are granted. Even in Graph API Explorer when writing post_id I cannot retrieve post's author details.
This is how I do it:
FacebookClient facebookClient = new DefaultFacebookClient(token);
String command = "orangepolska/feed";
Connection<Post> pagePosts = facebookClient.fetchConnection(command, Post.class);
ArrayList<String> postList = new ArrayList<String>();
String row;
for( List<Post> posts : pagePosts){
for (Post post : posts) {
if (post.getCreatedTime().after(startDate) && post.getCreatedTime().before(endDate)){
String message = post.getMessage();
CategorizedFacebookType postedBy = post.getFrom();
Post.Comments comments = post.getComments();
row = " owner: "+postedBy.getName()+" owner_id: "+postedBy.getId()+" post: "+message+" + " likes: "+post.getLikesCount() + "\n";
System.out.println(row);
postList.add(row);
}
}
}
return postList;
The problem occurs with various of functions like: getName(), getID(), getLikesCount() etc - these return null.
How can i fix it?
Thanks in advance.
You need to fetch the feed with the fields parameter so Facebook knows which fields you need to be filled. RestFB can only provide access to information that are given by Facebook ;)
Have a look here: http://restfb.com/#selecting-specific-fields
Norbert is correct but the link he posted did not work for me - you need to include "Parameter.with("fields", "from")" to get the user information.
Connection<Post> pagePosts = facebookClient.fetchConnection(command, Post.class, Parameter.with("fields", "from"));

access event by Facebook API

I'm trying to get information about event, to which I am invited.
I created access token in Open Graph page with all available permission and I use it.
I can fetch one event, but I can't see another, which I care. I noticed that event is "invite only", but it's settings are beyond my control.
It doesn't show in my events/maybe (when I clicked "maybe"), and when I try to access it by ID (graph.facebook.com/id), I get error message "Unsupported get request.".
I tried:
RestFB (Java) - this is my purpose
PHP SDK
JavaScript SDK
Can I do something more except using FQL?
I read about it and I want to use simple request to get event, as mentioned on this page: https://developers.facebook.com/docs/graph-api/reference/event/.
I can attach code if if this helps.
Thank You very much to look at this.
EDIT:
Java code:
FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
String attending = facebookClient.fetchObject("{event-id}/attending", String.class);
System.out.println("Attending: " + attending);
It works like a charm with one event, but fails (return empty array of data) on another event (I was invited to both).
JavaScript code:
FB.api(
'https://graph.facebook.com/{event-id}',
'get',
null,
function(response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
alert('test');
response['data'].forEach(function(entry) {
alert(entry['object']['name']) ;
});
}
}
);
Doesn't return error, but response['data'] array is empty, while in another case contains properly data.
EDIT 2:
Furthermore, I tried FQL with restFB. It similary doesn't work - following code returns only one event, such as http requests.
FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
String query = "SELECT name, eid FROM event where eid = {event1-id} OR eid = {event2-id}";
List<FqlUser> event = facebookClient.executeFqlQuery(query, FqlUser.class);
System.out.println("Events: " + event);
You can write a FQL query for all events you gave a (non-declining) rsvp feedback for:
select eid, uid, rsvp_status from event_member where uid=me()
If you want to see the according event data, use this:
select eid, name, description, start_time, venue, location, creator, host from event where eid in (select eid from event_member where uid=me())
Please note what is written about permissions to the event table in the docs: https://developers.facebook.com/docs/reference/fql/event/#permissions
You should be able to request FQL via the JS SDK like this:
FB.api(
'https://graph.facebook.com/fql?q=' + encodeURIComponent("select eid, name, description, start_time, venue, location, creator, host from event where eid in (select eid from event_member where uid=me())"),
'get',
...);
Seems to works as expected now. I think that was a bug in facebook itself.

Rally Rest Api: Get User's Email Address from Defect

With Rally's rest api, how can I query to find a user's email address?
For instance, I have this query to get a defect which contains the full name of the user who opened it and the user who owns the defect:
QueryRequest defectRequest = new QueryRequest("defect");
defectRequest.setFetch(new Fetch("Project", "LastUpdateDate", "FormattedId"));
defectRequest.setQueryFilter(new QueryFilter("Project.Name", "=", rallyProjectName).and(new QueryFilter("LastUpdateDate", ">", defectTimestamp.getTimestamp())));
QueryResponse projectDefects = rallyApi.query(defectRequest);
Now I'd like to take the Submitted By and Owner users from the defect and get their email addresses.
Make certain to include the fields "Owner" and "SubmittedBy" on your Fetch for the Defects:
defectRequest.setFetch(new Fetch("Project", "LastUpdateDate", "FormattedId", "Owner", "SubmittedBy"));
Then the Owner and SubmittedBy fields on each returned Defect (if populated in Rally and not null) will have a reference to the corresponding User object in Rally. Then your inclination to do a second request for this is spot on. It's easiest to just use that ref and do a GetRequest straight against the ref. Here's how on the Owner field as an example (forgive the clumsy try/catch block - it's catching empty Owner fields):
QueryResponse projectDefects = restApi.query(defectRequest);
if (projectDefects.wasSuccessful()) {
for (JsonElement result : projectDefects.getResults()) {
JsonObject defect = result.getAsJsonObject();
try {
JsonObject ownerJsonObject = defect.get("Owner").getAsJsonObject();
String ownerRef = ownerJsonObject.get("_ref").getAsString();
GetRequest ownerRequest = new GetRequest(ownerRef);
GetResponse ownerResponse = restApi.get(ownerRequest);
JsonObject ownerObj = ownerResponse.getObject();
System.out.println(String.format("Read owner. EmailAddress = %s",
ownerObj.get("EmailAddress").getAsString()));
} catch (java.lang.IllegalStateException ise) {
// System.out.println("IllegalStateException caught: ");
// ise.printStackTrace();
}
}
}

Get an array of user photos using FQL

I'm to get a list of the users photos (one's they've been tagged in) using FQL.
Basically I've go an array object like so: _imageAddressArray.
I can retrieve the users' photos using graphApi so I know it works, problem with graphAPi is that it's too slow (+15 seconds min for 100 photos).
So far I've got:
//New Stuff
FQL fql = new FQL(facebook);
String FQLResult = null;
try
{
_userGallery = graphApi.getPhotosMy(_noOfPhotos);
FQLResult = fql.fqlQuery("SELECT object_id, src_small FROM photo");
}
catch (EasyFacebookError e)
{
e.printStackTrace();
}
System.out.println("FQL Result" + FQLResult);
This returns the error: 601, any ideas anyone?
Of course ideally FQLResult will be a string[] (string array)
You're getting an error because you don't have a WHERE clause in your FQL statement that references one of the indexed columns -- shown with a "*" here
To get the photos using FQL that your user has been tagged in, try this:
SELECT object_id, src_small FROM photo WHERE object_id IN
(SELECT object_id FROM photo_tag WHERE subject = me())

Categories