gpt4 book ai didi

android - Facebook 个人资料图片 Android 返回 null

转载 作者:行者123 更新时间:2023-11-29 14:19:50 26 4
gpt4 key购买 nike

以前我得到这样的 Facebook 用户个人资料图片,直到最近一切正常。

但是现在每次都返回null。

这是网址:

"http://graph.facebook.com/"+userID+"/picture?height=100&type=normal&width=100"

这会不会是因为来自 Facebook 的重定向?因为如果您在浏览器中打开此 URL,您将被重定向到类似这样的内容:https://fbcdn-profile-a.akamaihd.net/......。有办法解决这个问题吗?

这是我的异步任务:

public class GetUserPicture extends AsyncTask<String, Void, Bitmap> {
ImageView profileImage;

public GetUserPicture(ImageView profileImage) {
this.profileImage = profileImage;
}

@Override
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Log.d("SHOW CORRECT URL", urldisplay);
Bitmap bitmap = null;
try {
URL url = new URL(urldisplay);
bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
HttpURLConnection.setFollowRedirects(true);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}

@Override
protected void onPostExecute(Bitmap result) {
if (result != null) {
Log.d("Not null", "NOT NULLL");
}
profileImage.setImageBitmap(getRoundedCornerBitmap(result, 70));
}

protected static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Config.ARGB_8888);

BitmapShader bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint pnt = new Paint();
pnt.setAntiAlias(true);
pnt.setShader(bitmapShader);

Canvas canvas = new Canvas(output);

final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;

paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);


return output;
}

我正在从 facebook 获取这张图片,将其弄圆然后显示。但是两周前它曾经工作得很好!如果我传递看起来像这样的重定向 url:https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t1.0-1/c12.12.155.155/s100x100/。 ...jpg 然后显示图像!

这里是错误:

03-31 12:05:08.482: D/skia(14479): --- SkImageDecoder::Factory returned null
03-31 12:05:08.482: D/AndroidRuntime(14479): Shutting down VM
03-31 12:05:08.482: W/dalvikvm(14479): threadid=1: thread exiting with uncaught exception (group=0x41675d40)
03-31 12:05:08.484: E/AndroidRuntime(14479): FATAL EXCEPTION: main
03-31 12:05:08.484: E/AndroidRuntime(14479): Process: com.hitchhiker.mobile, PID: 14479
03-31 12:05:08.484: E/AndroidRuntime(14479): java.lang.NullPointerException
03-31 12:05:08.484: E/AndroidRuntime(14479): at com.hitchhiker.mobile.asynctasks.GetUserPicture.getRoundedCornerBitmap(GetUserPicture.java:54)
03-31 12:05:08.484: E/AndroidRuntime(14479): at com.hitchhiker.mobile.asynctasks.GetUserPicture.onPostExecute(GetUserPicture.java:50)
03-31 12:05:08.484: E/AndroidRuntime(14479): at com.hitchhiker.mobile.asynctasks.GetUserPicture.onPostExecute(GetUserPicture.java:1)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.os.AsyncTask.finish(AsyncTask.java:632)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.os.Handler.dispatchMessage(Handler.java:102)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.os.Looper.loop(Looper.java:136)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.app.ActivityThread.main(ActivityThread.java:5102)
03-31 12:05:08.484: E/AndroidRuntime(14479): at java.lang.reflect.Method.invokeNative(Native Method)
03-31 12:05:08.484: E/AndroidRuntime(14479): at java.lang.reflect.Method.invoke(Method.java:515)
03-31 12:05:08.484: E/AndroidRuntime(14479): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
03-31 12:05:08.484: E/AndroidRuntime(14479): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
03-31 12:05:08.484: E/AndroidRuntime(14479): at dalvik.system.NativeStart.main(Native Method)
03-31 12:05:08.743: D/skia(14479): --- SkImageDecoder::Factory returned null
03-31 12:05:09.023: D/skia(14479): --- SkImageDecoder::Factory returned null
03-31 12:05:09.286: D/skia(14479): --- SkImageDecoder::Factory returned null
03-31 12:05:09.526: D/skia(14479): --- SkImageDecoder::Factory returned null
03-31 12:05:09.813: D/skia(14479): --- SkImageDecoder::Factory returned null

最佳答案

我不确定,但您可以尝试使用实际网址(fb 重定向到的网址)。

要获取此 url,请使用 redirect=0,就像这样-

"http://graph.facebook.com/"+userID+"/picture?height=100&type=normal&width=100&redirect=0"

然后你会得到响应——

{
data: {
url: "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/23122_595273610_9552621_q.jpg",
is_silhouette: false
}
}

从字典中获取此 url,然后尝试。我不确定,但它有帮助。

但如果它不起作用,那么它与您的代码有关,我建议您打印确切的错误/异常。

编辑:

我发现:

Auto redirection works automatically when original and redirected protocols are same.

因此,尝试从 https 而不是 http 加载图像:“https://graph.facebook.com/USER_ID/picture ”;因为图片的 url 是“https://fbcdn-profile-a.akamaihd.net/ ...”

然后 BitmapFactory.decodeStream 将再次工作。

关于android - Facebook 个人资料图片 Android 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22755247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com