1

在我试图获取用户信息的简单 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。因此,将不胜感激任何帮助。

4

1 回答 1

0

真是愚蠢的错误!让我浪费了几天......在“api.tumblr.com/v2/user/info” URL 中添加 http:// 前缀后一切正常!

于 2012-12-27T00:39:42.220 回答