2012-12-25 60 views
1

在我的簡單tumblr客戶端試圖獲取用戶信息。 檢索訪問和請求令牌是可以的。Android:signpost lib簽名請求拋出NullPointerException

一些代碼片段:

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和路標lib。所以,將不勝感激任何幫助。

回答

0

這是如此虛假的錯誤! 並且讓我浪費了幾天... 在向「api.tumblr.com/v2/user/info」URL添加http://前綴後,所有工作正常!

+0

您可以將完整的代碼和授權部分一起發給我嗎? – Manikandan

相關問題