我设法将Fb与Parse集成,并能够登录/注册并填充他们的名字,电子邮件解析。但是,当我尝试检索Facebook图片并存储到数据库中时,它根本不起作用。我的代码在makeMeRequest()下面如下,我在登录过程完成后调用它。
感谢您对此的专家帮助(我尝试了很多从网上找到的方法,但没有一种方法可行)。我不知道我在这里是否遗漏了什么。欣赏一个lor。感谢。
private void makeMeRequest() {
Request request = Request.newMeRequest(ParseFacebookUtils.getSession(),
new Request.GraphUserCallback() {
@Override
public void onCompleted(final GraphUser user, Response response) {
if (user != null) {
// Create a JSON object to hold the profile info
JSONObject userProfile = new JSONObject();
try {
// Populate the JSON object
userProfile.put("facebookId", user.getId());
userProfile.put("username", user.getName());
currentUser.setUsername(user.getFirstName());
currentUser.setEmail(user.asMap().get("email").toString());
AsyncTask<Void, Void, Bitmap> t = new AsyncTask<Void, Void, Bitmap>(){
protected Bitmap doInBackground(Void... p) {
Bitmap bm = null;
try {
URL aURL = new URL("http://graph.facebook.com/"+ user.getId()+"/picture?type=large");
URLConnection conn = aURL.openConnection();
conn.setUseCaches(true);
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bm;
}
protected void onPostExecute(Bitmap bm){
Drawable drawable = new BitmapDrawable(getResources(), bm);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
byteArray = FileHelper.reduceImageForUpload(byteArray);
ParseFile file = new ParseFile("profile_pix", byteArray);
currentUser.put(ParseConstants.KEY_FILE, file);
}
};
t.execute();
try {
currentUser.save();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Show the user info
//updateViewsWithProfileInfo();
} catch (JSONException e) {
}
} else if (response.getError() != null) {
if ((response.getError().getCategory() == FacebookRequestError.Category.AUTHENTICATION_RETRY)
|| (response.getError().getCategory() == FacebookRequestError.Category.AUTHENTICATION_REOPEN_SESSION)) {
//onLogoutButtonClicked();
} else {
}
}
}
});
request.executeAsync();
}