Android:signpost lib签名请求抛出NullPointerException

时间:2012-12-25 19:21:57

标签: android oauth tumblr signpost

在我的简单tumblr客户端尝试获取用户信息。 检索访问权限和请求令牌是可以的。

一些代码段:

CommonsHttpOAuthProvider provider = new CommonsHttpOAuthProvider(
            "http://www.tumblr.com/oauth/request_token", 
            "http://www.tumblr.com/oauth/access_token", 
            "http://www.tumblr.com/oauth/authorize");
    provider.setOAuth10a(true);

OAuthConsumer consumer = new CommonsHttpOAuthConsumer(
            app.TUMBLR_OAUTH_CONSUMER_KEY,
            app.TUMBLER_CONSUMER_SECRET_KEY);

通过浏览器进行用户身份验证:

String authUrl = provider.retrieveRequestToken(consumer,
                    "everyshare://everyshare.com/ok");
            // savint token and token secret...
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri
                    .parse(authUrl));
            startActivity(browserIntent);

经过身份验证后:

public void onResume() {
    super.onResume();

    Uri uri = this.getIntent().getData();
    if (uri != null) {
        oauth_verifier = uri.getQueryParameter("oauth_verifier");

        try {
                            // consumer with the request token and secret
            provider.retrieveAccessToken(consumer, oauth_verifier);

            String url = "api.tumblr.com/v2/user/info";

            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpGet request = new HttpGet(url);
            consumer.sign(request); // here's throws exception

...

错误日志

  oauth.signpost.exception.OAuthMessageSignerException: java.lang.NullPointerException  at 
  oauth.signpost.signature.SignatureBaseString.generate(SignatureBaseString.java:60) at 
  oauth.signpost.signature.HmacSha1MessageSigner.sign(HmacSha1MessageSigner.java:51) at
  oauth.signpost.AbstractOAuthConsumer.sign(AbstractOAuthConsumer.java:97) at 
  oauth.signpost.AbstractOAuthConsumer.sign(AbstractOAuthConsumer.java:107) at 
  com.skelpo.everyshare.activitys.TumblrSettingsAct.onResume(TumblrSettingsAct.java:154) at 
  android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150) at 
  android.app.Activity.performResume(Activity.java:3882) at 
  android.app.ActivityThread.performResumeActivity(ActivityThread.java:2191) at
  android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2228) at
  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1721) at 
  android.app.ActivityThread.access$1500(ActivityThread.java:124) at 
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:968) at
  android.os.Handler.dispatchMessage(Handler.java:99) at 
  android.os.Looper.loop(Looper.java:130) at 
  android.app.ActivityThread.main(ActivityThread.java:3806) at 
  java.lang.reflect.Method.invokeNative(Native Method) at 
  java.lang.reflect.Method.invoke(Method.java:507) at 
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at 
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at 
  dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at 
  oauth.signpost.signature.SignatureBaseString.normalizeRequestUrl(SignatureBaseString.java:66) at 
  oauth.signpost.signature.SignatureBaseString.generate(SignatureBaseString.java:54)

这是我第一次使用OAuth和signpost lib。所以对任何帮助都会感激不尽。

1 个答案:

答案 0 :(得分:0)

这是假错误! 让我浪费几天...... 将http://前缀添加到“api.tumblr.com/v2/user/info”URL后,一切正常!