Noob Question (can't get the example to work)

106 views
Skip to first unread message

Tiago

unread,
Nov 27, 2011, 1:24:19 PM11/27/11
to BatchFB
Sorry for disturbing you guys with (probably) such a silly question,
but I already tried everything i could =/

I was trying to use RestFB, but it's just to slow, it was taking about
40secs just to retrieve the albuns covers in a page, so i found
BatchFB, the only problem is: it's way more complex.

So.. my problem is, I can't make anything to work, I aways get this
irritating exception:

Name: org.codehaus.jackson.map.JsonMappingException
Message: "No suitable constructor found for type [simple type, class
controller.Albuns$Album]: can not instantiate from JSON object (need
to add/enable type information?) at [Source: N/A; line: -1, column:
-1] (through reference chain:
com.googlecode.batchfb.type.Paged["data"])".

My code (Both class and method are inside another class):

* Method being executed:

private void recuperarAlbuns(){
Batcher fbBatcher = new FacebookBatcher(MY_ACCESS_TOKEN);
PagedLater<Album> page = fbBatcher.paged(pageName + "/albums",
Album.class);
System.out.println(page.get().size());
}

* class Album:

public class Album{
private String id;
private String name;
private String description;
private String link;
private String type;
private int count;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getLink() {
return link;
}

public void setLink(String link) {
this.link = link;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public int getCount() {
return count;
}

public void setCount(int count) {
this.count = count;
}
}

Thanks in advance for any answer.
Tiago

Jeff Schnitzer

unread,
Nov 27, 2011, 2:34:38 PM11/27/11
to bat...@googlegroups.com
It looks like you have defined your class Album as a non-static inner class on Albums.  Either make Album static or move it out to a standalone class... json mappers can't generate nested inner classes because they have pointers to their parent classes.  That makes no sense without the context of the parent class.

Jeff
--
I am the 20%

Tiago Peres França

unread,
Nov 27, 2011, 2:55:58 PM11/27/11
to bat...@googlegroups.com
Thank you for the answer Jeff, that was exactly the problem! I just made "Album" static and it worked.

Tiago

2011/11/27 Jeff Schnitzer <je...@infohazard.org>

Mark Allen

unread,
Nov 28, 2011, 8:32:06 AM11/28/11
to BatchFB
Hi Tiago -

You mentioned this:

> I was trying to use RestFB, but it's just to slow, it was taking about
> 40secs just to retrieve the albuns covers in a page, so i found
> BatchFB, the only problem is: it's way more complex.

If you were seeing a fetch of PAGE_ID/albums take 40 seconds,
something was up with either your network connection or Facebook, not
RestFB (or BatchFB). If there was something else going on you didn't
mention that was causing performance problems with RestFB, please let
me know off-chain so we don't totally hijack this thread.

Thanks
Mark

Tiago Peres França

unread,
Nov 29, 2011, 4:23:17 PM11/29/11
to bat...@googlegroups.com
Hi Mark,

To fetch PAGE_ID/albums it takes from 6 to 9 secs, for both RestFB and BatchFB (it's just one request). I don't know if it's normal, maybe i have some connection problem.

9 secs to load a page is too much for my application, if it's really the time it takes to fetch an album i'll to rethink my application =/.

The album i'm talking about is from coca-cola's page.

The 40 secs i was talking about was to fetch the album covers of each album in the album page. The cover attribute gives actually the id to the picture represenjting the album cover, so my algorithm was:

Fetch albums from graph.facebook.com/cocacola/albums;
For each album in albums do:
Fetch picture from graph.facebook.com/album.getCover()
album.setCoverThumnail(picture.getThumbnail);
end for;

So, i actually had n + 1 requests to facebook, where n is the number of albums fetched from graph.facebook.com/cocacola/albums.

Is 6-9 secs to fetch a page full of albums normal?

Tiago

2011/11/28 Mark Allen <m...@xmog.com>

Mark Allen

unread,
Nov 29, 2011, 4:35:04 PM11/29/11
to BatchFB
6-9 seconds per fetch is pretty bad - I don't have experience with
loading album pages so I don't know if that's normal, but I trust your
numbers are correct. Hopefully it's just a temporary FB hiccup.

Is it possible to reduce the n+1 requests you have to make by using
the Batch API? https://developers.facebook.com/docs/reference/api/batch/

Both RestFB and BatchFB support this, it should hopefully be a nice
speedup over making lots of individual requests.

Thanks
Mark

Tiago Peres França

unread,
Nov 30, 2011, 4:16:41 AM11/30/11
to bat...@googlegroups.com
Thank you for the info, i`m gonna reed the Facebook documentation of batch API.

Tiago

2011/11/29 Mark Allen <m...@xmog.com>

Jeff Schnitzer

unread,
Nov 30, 2011, 8:23:10 AM11/30/11
to bat...@googlegroups.com
FWIW, BatchFB specifically isolates you from the batch API - if you're using BatchFB then you are using the batch API.  Just make sure to create all the Later<?> objects you want *before* you call Later<?>.get() on any of them.  Your code should roughly look like this:

get the list of albums (the "+1" query)
for each album in the list
    Later<Album> album = batcher.request(the album)
    listOfAlbums.add(album)
for (Later<Album> later: listOfAlbums)
    process later.get()

Or, if you want to do it by hand, you can read up on the batch API and use RestFB.  If you are struggling with the BatchFB API this may be your best option.

Jeff
--
We are the 20%

Tiago Peres França

unread,
Nov 30, 2011, 9:34:17 AM11/30/11
to bat...@googlegroups.com
I'm gonna try to use BatchFB firstly. I thought that reading Facebook's documentation I could learn how to construct queries Iike the one saw in the example below:
Later<List<User>> myFriends = batcher.query(
   
"SELECT uid, first_name, pic_square FROM user WHERE uid IN" +
   
"(SELECT uid2 FROM friend WHERE uid1 = " + myId + ")", User.class
);
I thought maybe I could do somethinhg like this to fetch all album covers at once, but i didn't find anything about queries at BatchFB's page.

Thanks
Tiago

2011/11/30 Jeff Schnitzer <je...@infohazard.org>

Jeff Schnitzer

unread,
Nov 30, 2011, 9:49:50 AM11/30/11
to bat...@googlegroups.com
For the most part queries are pretty much just like any other facebook request, you just use batcher.query() and FQL instead of batcher.graph() and standard graph paths.  Look at Facebook's documentation for FQL; you might very well be able to construct a single query that gets all your results.  At worst, you can probably make it a multiquery by naming the first result set and using it in the second - BatchFB lets you do this easily too without learning how to issue a multiquery request.

I'm not in a good position timewise to help you figure out the FQL, but if you can figure out the request you want to issue, I can help you make a BatchFB request out of it.

Jeff
Reply all
Reply to author
Forward
0 new messages