我意识到 Jumblr,一个适用于 Android 的 Tumblr APi 并没有很好地记录我们如何实际实施一个。我已成功在我的应用上授权我的帐户。就这样。根据Jumblr 的自述文件,你所要做的就是
JumblrClient client = new JumblrClient("consumer_key", "consumer_secret");
client.setToken("oauth_token", "oauth_token_secret");
其中消费者密钥和秘密已经在我的应用程序中设置,并且 oauth_token 和 token_secret 在用户登录时由应用程序获取。但是,我收到了类似的错误
org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service.
完整的日志:
08-12 19:55:03.212: E/AndroidRuntime(27896): FATAL EXCEPTION: main
08-12 19:55:03.212: E/AndroidRuntime(27896): java.lang.RuntimeException: Unable to start activity ComponentInfo{dev.example.tumblr/dev.example.tumblr.MainActivity}: org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service.
08-12 19:55:03.212: E/AndroidRuntime(27896): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
08-12 19:55:03.212: E/AndroidRuntime(27896): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
08-12 19:55:03.212: E/AndroidRuntime(27896): at android.app.ActivityThread.access$600(ActivityThread.java:153)
08-12 19:55:03.212: E/AndroidRuntime(27896): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
08-12 19:55:03.212: E/AndroidRuntime(27896): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 19:55:03.212: E/AndroidRuntime(27896): at android.os.Looper.loop(Looper.java:137)
08-12 19:55:03.212: E/AndroidRuntime(27896): at android.app.ActivityThread.main(ActivityThread.java:5227)
08-12 19:55:03.212: E/AndroidRuntime(27896): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 19:55:03.212: E/AndroidRuntime(27896): at java.lang.reflect.Method.invoke(Method.java:511)
08-12 19:55:03.212: E/AndroidRuntime(27896): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
08-12 19:55:03.212: E/AndroidRuntime(27896): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
08-12 19:55:03.212: E/AndroidRuntime(27896): at dalvik.system.NativeStart.main(Native Method)
08-12 19:55:03.212: E/AndroidRuntime(27896): Caused by: org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service.
08-12 19:55:03.212: E/AndroidRuntime(27896): at org.scribe.model.Request.send(Request.java:70)
08-12 19:55:03.212: E/AndroidRuntime(27896): at org.scribe.model.Request.send(Request.java:76)
08-12 19:55:03.212: E/AndroidRuntime(27896): at dev.example.tumblr.library.request.RequestBuilder.get(RequestBuilder.java:71)
08-12 19:55:03.212: E/AndroidRuntime(27896): at dev.example.tumblr.library.JumblrClient.user(JumblrClient.java:65)
08-12 19:55:03.212: E/AndroidRuntime(27896): at dev.example.tumblr.MainActivity.onCreate(MainActivity.java:59)
08-12 19:55:03.212: E/AndroidRuntime(27896): at android.app.Activity.performCreate(Activity.java:5104)
08-12 19:55:03.212: E/AndroidRuntime(27896): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-12 19:55:03.212: E/AndroidRuntime(27896): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
08-12 19:55:03.212: E/AndroidRuntime(27896): ... 11 more
08-12 19:55:03.212: E/AndroidRuntime(27896): Caused by: android.os.NetworkOnMainThreadException
08-12 19:55:03.212: E/AndroidRuntime(27896): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
08-12 19:55:03.212: E/AndroidRuntime(27896): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
08-12 19:55:03.212: E/AndroidRuntime(27896): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
08-12 19:55:03.212: E/AndroidRuntime(27896): at java.net.InetAddress.getAllByName(InetAddress.java:214)
08-12 19:55:03.212: E/AndroidRuntime(27896): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
08-12 19:55:03.212: E/AndroidRuntime(27896): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
08-12 19:55:03.212: E/AndroidRuntime(27896): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
08-12 19:55:03.212: E/AndroidRuntime(27896): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
08-12 19:55:03.212: E/AndroidRuntime(27896): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
08-12 19:55:03.212: E/AndroidRuntime(27896): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
08-12 19:55:03.212: E/AndroidRuntime(27896): at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
08-12 19:55:03.212: E/AndroidRuntime(27896): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
08-12 19:55:03.212: E/AndroidRuntime(27896): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
08-12 19:55:03.212: E/AndroidRuntime(27896): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
08-12 19:55:03.212: E/AndroidRuntime(27896): at org.scribe.model.Response.<init>(Response.java:29)
08-12 19:55:03.212: E/AndroidRuntime(27896): at org.scribe.model.Request.doSend(Request.java:117)
08-12 19:55:03.212: E/AndroidRuntime(27896): at org.scribe.model.Request.send(Request.java:66)
我知道我必须对 Oauth 做点什么。但它是什么?我在以前的 Oauth for Twitter 方面经验很少。
提前致谢。