Graph call to simple string or enable diagnostics ???

40 views
Skip to first unread message

John Gentilin

unread,
Aug 15, 2012, 8:04:21 PM8/15/12
to bat...@googlegroups.com
I am trying to debug a graph call and I would like to just fetch the raw results of .get() to see
what batchfb is seeing. The code block below returns null for "rsvp_status" but if I execute
the same exact query in Graph Explorer it gives me a value. Other times I just want the raw
string back, i.e. the new graph call /oauth/access_token does not return JSON. When I map
my request to a simple string, it will compile but it always tries to serialize it through Jackson
JSON and throws and exception.

So

1) is there a way to turn on logging so I can see the http request / response ?

2) Can I map a request to a non JSON object ?

      Batcher batcher = new FacebookBatcher(accessToken);
      String status = "";
      Later<JsonNode> myRSVP1 = batcher.graph(fbEventID + "/attending/" + fbUserID, JsonNode.class);
      status = myRSVP1.get().get("rsvp_status").asText();

      Later<String> myRSVP = batcher.graph(fbEventID + "/attending/" + fbUserID, String.class);
      status = myRSVP.get();

Thank you
John Gentilin



Jeff Schnitzer

unread,
Aug 15, 2012, 8:11:35 PM8/15/12
to bat...@googlegroups.com
On Wed, Aug 15, 2012 at 5:04 PM, John Gentilin <gen...@gmail.com> wrote:
> I am trying to debug a graph call and I would like to just fetch the raw
> results of .get() to see
> what batchfb is seeing. The code block below returns null for "rsvp_status"
> but if I execute
> the same exact query in Graph Explorer it gives me a value. Other times I
> just want the raw
> string back, i.e. the new graph call /oauth/access_token does not return
> JSON. When I map
> my request to a simple string, it will compile but it always tries to
> serialize it through Jackson
> JSON and throws and exception.
>
> So
>
> 1) is there a way to turn on logging so I can see the http request /
> response ?

Funny, this came up last week in the most recent thread. Yes:

BatchFB logs the raw request and response via java.util.logging - see
RequestBuilder. Turn this on in your logging.properties:

com.googlecode.batchfb.level = FINEST

This really should go in the documentation.

> 2) Can I map a request to a non JSON object ?
>
> Batcher batcher = new FacebookBatcher(accessToken);
> String status = "";
> Later<JsonNode> myRSVP1 = batcher.graph(fbEventID + "/attending/" +
> fbUserID, JsonNode.class);
> status = myRSVP1.get().get("rsvp_status").asText();
>
> Later<String> myRSVP = batcher.graph(fbEventID + "/attending/" +
> fbUserID, String.class);
> status = myRSVP.get();

I don't know offhand what Jackson will do if you try to read a json
structure into a String. Try it. Note that you can use Object.class
and get Map/List structures back.

Jeff

John Gentilin

unread,
Aug 15, 2012, 9:22:34 PM8/15/12
to bat...@googlegroups.com
Enabling logging only logs the request, for some reason the response was not there.
FINER: POSTing: https://graph.facebook.com/
Aug 16, 2012 12:46:28 AM com.googlecode.batchfb.util.RequestBuilder$1 setup
FINER: POST data is: access_token=AAAD60&batch=%5B%7B%22method%22%3A%22GET%22%2C%22relative_url%22%3A%2235%2Fattending%2F1000032%22%7D%5D


If I map the response to a String, I get this exception
java.lang.IllegalArgumentException: Can not deserialize instance of java.lang.String out of START_OBJECT token
 at [Source: N/A; line: -1, column: -1]

If I map to Object, some child of the cached object has what seemed like well formed JSON.
{name=Pic Rollr, id=1000032, rsvp_status=attending}  note: id's are shortened.

When I went back to mapping the response to a JsonNode, I noticed that the response fell under
the "data" element. So in the debugger,

((JsonNode)myRSVP1.get()).get("data");
returns
(org.codehaus.jackson.node.ArrayNode) [{"name":"Pic Rollr","id":"1000032","rsvp_status":"attending"}]

but the top level data={} is not in the raw response.

I was expecting
myRSVP1.get().get("rsvp_status") to return attending, it returns null.

This is for the code.

      Batcher batcher = new FacebookBatcher(accessToken);
      Later<JsonNode> myRSVP1 = batcher.graph(fbEventID + "/attending/" + fbUserID, JsonNode.class);
      myRSVP1.get();

and inspecting myRSVP1..

-John G

Aug 16, 2012 12:46:28 AM com.googlecode.batchfb.util.RequestBuilder execute

John Gentilin

unread,
Aug 15, 2012, 9:31:09 PM8/15/12
to bat...@googlegroups.com
nm, the data element is there.. totally missed it..


On Wednesday, August 15, 2012 5:04:21 PM UTC-7, John Gentilin wrote:

Jeff Schnitzer

unread,
Aug 15, 2012, 11:04:01 PM8/15/12
to bat...@googlegroups.com
On Wed, Aug 15, 2012 at 6:22 PM, John Gentilin <gen...@gmail.com> wrote:
> Enabling logging only logs the request, for some reason the response was not
> there.
> FINER: POSTing: https://graph.facebook.com/
> Aug 16, 2012 12:46:28 AM com.googlecode.batchfb.util.RequestBuilder$1 setup
> FINER: POST data is:
> access_token=AAAD60&batch=%5B%7B%22method%22%3A%22GET%22%2C%22relative_url%22%3A%2235%2Fattending%2F1000032%22%7D%5D

I suspect you tried to narrow the logging to the RequestBuilder.
Enable logging for com.googlecode.batchfb. Because of the highly
asynchronous nature of everything, the RequestBuilder never sees the
content of the result - that happens later. It's actually Batch that
logs the response.

The request & response are the only things that BatchFB logs right
now, so you're safe with this:

com.googlecode.batchfb.level = FINEST

BTW for Facebook "connections" (ie things that have a 'data'
attribute) you probably want the paged() method on Batcher. It
understands Facebook's structure with data, next, previous, etc.

Jeff

John Gentilin

unread,
Aug 16, 2012, 4:54:12 AM8/16/12
to bat...@googlegroups.com, je...@infohazard.org

The connections/data thing was my bad, I am guessing I assumed that since I was
querying for a single user the data would not be paged.. Although I must of looked
at it a 100 times in Graph API Explorer.. I changed it to a PagedLater then a get(0)
to get the first element...

For the logging, my entire logging.properties file is
.level=INFO
com.googlecode.batchfb.level=FINEST

The is an App Engine servlet running on local host..

Thank you for your help...

-John G

Jeff Schnitzer

unread,
Aug 16, 2012, 11:24:25 AM8/16/12
to bat...@googlegroups.com
I don't know what to say about the logging. When I look in my log
files (both dev and production) I see the response from Facebook.

FINEST: Batch$2.get: Response
is: [{"code":200,"headers":[{"name":"Access-Control-Allow-Origin","value":"*"},{"name":"Cache-Control","value":"private,
no-cache, no-store,
must-revalidate"},{"name":"Connection","value":"close"},{"name":"Content-Type","value":"text/javascript;
charset=UTF-8"},{"name":"ETag","value":"\"4c5417e792d96dea7a50601ccb3a21dde0bff90b\""},{"name":"Expires","value":"Sat,
01 Jan 2000 00:00:00
GMT"},{"name":"Last-Modified","value":"2012-03-11T02:48:39+0000"},{"name":"Pragma","value":"no-cache"}],"body":
...

You can see the log statement in Batch.java line 416.

Jeff

John Gentilin

unread,
Aug 16, 2012, 5:44:10 PM8/16/12
to bat...@googlegroups.com, je...@infohazard.org
Log problem fixed, needed to upgrade to 2.1.2 from 2.1.1..

Thanks again for your help.
-John G
Reply all
Reply to author
Forward
0 new messages