gpt4 book ai didi

android - 如何通过更高分辨率的 graphRequest 加载 Facebook 封面照片? [安卓 | Facebook v2.3]

转载 作者:行者123 更新时间:2023-12-05 00:22:04 27 4
gpt4 key购买 nike

我正在编写一个 Android 应用程序,我需要用户使用 Facebook 登录。

登录工作正常,我也得到了一张个人资料图片,但图片的分辨率非常低 - 大约 50 px x 50 px。有没有可能得到一个更好的?

以下代码用于在 Facebook 登录过程和 GraphRequest.newMeRequest 之后加载图像.

public class LoadFacebookUserPicture extends AsyncTask<String, Void, Bitmap> {

private Context context;

public LoadFacebookUserPicture (Context context) {
this.context = context;
}

@Override
protected Bitmap doInBackground(String... params) {
try {
URL url = new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
FileOutputStream fos = context.openFileOutput("test.png", Context.MODE_PRIVATE);
myBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
return null;
} catch (Exception e) {
e.printStackTrace();
Log.e("LoadFacebookUserPicture", e.getMessage());
}
Log.e("LoadFacebookUserPicture", "Passt");
return null;
}

}

这是请求,在类 LoadFacebookUserPicture 中被调用。
  GraphRequest request = GraphRequest.newMeRequest(
currentAccessToken,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Save facebook data
SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(getString(R.string.userdata_facebook), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
try {
// Lese von FB json objekt
int fb_id = ((JSONObject) object).getInt("id");
String fb_name = ((JSONObject) object).getString("name");
String fb_gender = ((JSONObject) object).getString("gender");
String fb_link = ((JSONObject) object).getString("link");
JSONObject json_data = ((JSONObject) object).getJSONObject("picture").getJSONObject("data");
String fb_picture_url = json_data.getString("url");
// Schreibe in private shared pref der activity
editor.putInt(getString(R.string.fb_user_id), fb_id);
editor.putString(getString(R.string.fb_user_name), fb_name);
editor.putString(getString(R.string.fb_user_gender), fb_gender);
editor.putString(getString(R.string.fb_user_link), fb_link);
editor.putString(getString(R.string.fb_user_picture_url), fb_picture_url);
editor.commit();

String[] params = new String[1];
params[0] = fb_picture_url;
new LoadFacebookUserPicture(MainActivity.this).execute(params);
} catch (JSONException e) {
e.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,birthday,gender,link,picture");
request.setParameters(parameters);
request.executeAsync();

最佳答案

试试这个,这会给你一个更好的形象

http://graph.facebook.com/<fb_id >/picture?type=large

关于android - 如何通过更高分辨率的 graphRequest 加载 Facebook 封面照片? [安卓 | Facebook v2.3],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29710869/

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