私の単純な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と道標libでの私の最初の経験です。だからどんな助けにも感謝するでしょう。