Http status code null

1,603 views
Skip to first unread message

유정우

unread,
Mar 11, 2013, 7:48:20 AM3/11/13
to res...@googlegroups.com
i am making a program using android.

my state is that i got a accesstoken and make a connection using "FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);"

and when i run below sentence, get a http status code null

"Connection<Post> myFeed = facebookClient.fetchConnection("me/feed", Post.class); "

what is problem with me?

Mark Allen

unread,
Mar 11, 2013, 9:31:51 AM3/11/13
to res...@googlegroups.com
Hi there -

Can you include your stack trace?

Thanks
Mark

Licio Mazzeo

unread,
Apr 6, 2013, 1:52:57 PM4/6/13
to res...@googlegroups.com
Same problem here. If I fetch my friends list with facebook api for android, thats ok. but if i try tu use rest fb to fetch 
friends list i got this:
04-06 19:46:32.838: E/AndroidRuntime(6124): FATAL EXCEPTION: main
04-06 19:46:32.838: E/AndroidRuntime(6124): com.restfb.exception.FacebookNetworkException: A network error occurred while trying to communicate with Facebook: Facebook request failed (HTTP status code null)
04-06 19:46:32.838: E/AndroidRuntime(6124): at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:615)
04-06 19:46:32.838: E/AndroidRuntime(6124): at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:592)
04-06 19:46:32.838: E/AndroidRuntime(6124): at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:556)
04-06 19:46:32.838: E/AndroidRuntime(6124): at com.restfb.DefaultFacebookClient.fetchConnection(DefaultFacebookClient.java:219)
04-06 19:46:32.838: E/AndroidRuntime(6124): at org.pipe.android.medcenterapp.MainActivity$1.call(MainActivity.java:57)
04-06 19:46:32.838: E/AndroidRuntime(6124): at com.facebook.Session$3$1.run(Session.java:1190)
04-06 19:46:32.838: E/AndroidRuntime(6124): at android.os.Handler.handleCallback(Handler.java:725)
04-06 19:46:32.838: E/AndroidRuntime(6124): at android.os.Handler.dispatchMessage(Handler.java:92)
04-06 19:46:32.838: E/AndroidRuntime(6124): at android.os.Looper.loop(Looper.java:137)
04-06 19:46:32.838: E/AndroidRuntime(6124): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-06 19:46:32.838: E/AndroidRuntime(6124): at java.lang.reflect.Method.invokeNative(Native Method)
04-06 19:46:32.838: E/AndroidRuntime(6124): at java.lang.reflect.Method.invoke(Method.java:511)
04-06 19:46:32.838: E/AndroidRuntime(6124): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-06 19:46:32.838: E/AndroidRuntime(6124): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-06 19:46:32.838: E/AndroidRuntime(6124): at dalvik.system.NativeStart.main(Native Method)
04-06 19:46:32.838: E/AndroidRuntime(6124): Caused by: android.os.NetworkOnMainThreadException
04-06 19:46:32.838: E/AndroidRuntime(6124): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
04-06 19:46:32.838: E/AndroidRuntime(6124): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
04-06 19:46:32.838: E/AndroidRuntime(6124): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
04-06 19:46:32.838: E/AndroidRuntime(6124): at java.net.InetAddress.getAllByName(InetAddress.java:214)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
04-06 19:46:32.838: E/AndroidRuntime(6124): at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
04-06 19:46:32.838: E/AndroidRuntime(6124): at com.restfb.DefaultWebRequestor.executeGet(DefaultWebRequestor.java:99)
04-06 19:46:32.838: E/AndroidRuntime(6124): at com.restfb.DefaultFacebookClient$2.makeRequest(DefaultFacebookClient.java:597)
04-06 19:46:32.838: E/AndroidRuntime(6124): at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:609)
04-06 19:46:32.838: E/AndroidRuntime(6124): ... 14 more

Mark Allen

unread,
Apr 6, 2013, 2:41:54 PM4/6/13
to res...@googlegroups.com
I don't do much Android work, but I can tell you this is your problem:

Caused by: android.os.NetworkOnMainThreadException

Thanks
Mark

Licio Mazzeo

unread,
Apr 6, 2013, 2:45:34 PM4/6/13
to res...@googlegroups.com
mmmm ... maybe i have to execute the fetch code on another thread? I'll try...


2013/4/6 Mark Allen <m...@xmog.com>
--
You received this message because you are subscribed to a topic in the Google Groups "RestFB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/restfb/PXiFKPU4CLU/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to restfb+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Licio Mazzeo

unread,
Apr 6, 2013, 4:51:19 PM4/6/13
to res...@googlegroups.com
yes! that was the problem. 


2013/4/6 Licio Mazzeo <liz...@gmail.com>

Felipe Caldas

unread,
May 29, 2013, 6:18:11 AM5/29/13
to res...@googlegroups.com
Yes, that was the problem.

Any chances you guys can add to the RestFB docs something like "Make sure to call our methods from within a Background Thread so you dont run against the  android.os.NetworkOnMainThreadException issue on Android"

An example code is the following:

facebookClient = new DefaultFacebookClient(session.getAccessToken());

AsyncTask.execute(new Runnable() {
public void run() {
try {
User user = facebookClient.fetchObject("me", User.class);
Log.i(TAG, user.getFirstName());
} catch(com.restfb.exception.FacebookException ex) {
Log.i(TAG, "" + ex.getMessage());
}
}
});


Take care 
Felipe

Mark Allen

unread,
Jun 2, 2013, 10:48:58 AM6/2/13
to res...@googlegroups.com
If more people run into this, I'll update the docs, but as I understand it this is a basic Android development concept (network calls must not occur on the UI thread).

It does bring up a related point that it might be helpful for RestFB to support asynchronous versions of the methods in FacebookClient that return Future<Whatever>.  I'd have to think more about the best way to design that, however.

Thanks
Mark

Eric Nguyen

unread,
Jan 29, 2015, 9:45:59 PM1/29/15
to res...@googlegroups.com
Hi Mark,

Regardless of the platform e.g. Android, I think it'll definitely be useful to make RestFb asynchronous :)

Looking forward to that :)

Thanks,
Eric

Norbert Bartels

unread,
Jan 30, 2015, 3:45:19 AM1/30/15
to res...@googlegroups.com
Should be configurable :)
Reply all
Reply to author
Forward
0 new messages