Last active
December 31, 2015 12:59
-
-
Save takke/7990339 to your computer and use it in GitHub Desktop.
Twitter4J v3.0.5でDM添付画像を取得してみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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