Tumblr API - 适用于Android的Jumblr [OAuthConnectionException]

时间:2013-08-12 12:02:37

标签: android oauth tumblr

我意识到Jumblr,一个针对Android的Tumblr APi没有详细记录我们如何实际实现一个。我已经在我的应用上成功授权了我的帐户。就这样。根据{{​​3}},您所要做的就是

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.

完整logcat:

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没什么经验。

提前致谢。

2 个答案:

答案 0 :(得分:4)

问题在于NetworkOnMainThreadException而不是OAuth。从Android 3.0开始,所有网络操作都必须在后台线程上运行。将您对Jumblr的调用放在AsyncTask或类似的东西中。

答案 1 :(得分:0)

无法获取用户信息

是: consumer = new CommonsHttpOAuthConsumer(APP_CONSUMER_KEY,APP_CONSUMER_SECRET); provider = new CommonsHttpOAuthProvider(“请求令牌网址”, “访问令牌网址”,“授权网址”); provider.setOAuth10a(真); 尝试 { authUrl = provider.retrieveRequestToken(consumer,CALLBACK_URL); }

获得令牌和秘密后,我正在致电

api = new JumblrClient(TumblrLoginActivity.APP_CONSUMER_KEY,TumblrLoginActivity.APP_CONSUMER_SECRET); api.setToken(consumer.getToken(),consumer.getTokenSecret());

LOG错误:

org.scribe.exceptions.OAuthConnectionException:创建与远程服务的连接时出现问题。