Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@takke
Last active December 31, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takke/7990339 to your computer and use it in GitHub Desktop.
Save takke/7990339 to your computer and use it in GitHub Desktop.
Twitter4J v3.0.5でDM添付画像を取得してみた
// DM画像認証対応
MyLog.d("doDownloadImage, download image with twitter4j");
final Twitter twitter = TPUtil.getTwitterInstance(context);
try {
final Class<? extends Twitter> c = twitter.getClass();
final Method m = c.getDeclaredMethod("get", String.class);
m.setAccessible(true);
final HttpResponse res = (HttpResponse) m.invoke(twitter, rawImageUrl); // twitter.get(rawImageUrl);
final InputStream is = res.asStream();
image = BitmapFactory.decodeStream(is);
if (image == null) {
// ダウンロード失敗
MyLog.w(" download twitter image, image load error [" + rawImageUrl + "]");
return null;
}
} catch (Throwable th) {
MyLog.e(th);
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment