【发布时间】:2015-02-07 02:28:12
【问题描述】:
我尝试使用此 Android Picasso library, How to add authentication headers? 访问受保护的图像,该图像返回图像的 base64 版本。我的问题是毕加索总是失败。我不知道为什么。由于加载了配置文件详细信息,因此授权代码有效。只有图像不是。这是我的实现如何获取图像。
public class PicaAuth {
private static Picasso sPicasso;
private PicaAuth() {
}
public static Picasso getImageLoader(final Context context) {
if (sPicasso == null) {
Picasso.Builder builder = new Picasso.Builder(context);
builder.downloader(new CustomOkHttpDownloader(context));
sPicasso = builder.build();
}
return sPicasso;
}
private static class CustomOkHttpDownloader extends OkHttpDownloader {
public CustomOkHttpDownloader(Context context) {
super(context);
}
@Override
protected HttpURLConnection openConnection(final Uri uri) throws IOException {
HttpURLConnection connection = super.openConnection(uri);
connection.setRequestProperty("Authorization", Auth.getBearerAccessToken());
return connection;
}
}
}
主要活动
PicaAuth.getImageLoader(MainActivity.this)
.load(uri)
.into(mImage, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {
Log.d("Image Success");
}
@Override
public void onError() {
Log.e("Image Failed");
}
});
【问题讨论】:
标签: android