Not Able To Retrieve Profile Pic With Fb Login
I followed the tutorial of facebook on their official page: Facebook Login tutorial However, after I finished this I do can login, but it doesn't retrieve my profile picture. Anyon
Solution 1:
I think you are clear upto getting facebook useUserId and FacebookToken.
Profile picture get can be done in two ways:
1: Facebook has provided you a view for profile picture `ie ProfilePictureView
in place of imageview in xml layout file take this view.
At the time of loadng image in this view simply do
ProfilePictureView profilePictureView;
profilePictureView = (ProfilePictureView) findViewById(R.id.friendProfilePicture);
profilePictureView.setCropped(true);
profilePictureView.setProfileId(USER_ID);
2: Another Option is get profile picture with the help of facebook token
ImageView imgProfilePic12=(ImageView)findViewById(R.id.imgProfilePic);
newLoadProfileImage(imgProfilePic12)
.execute("https://graph.facebook.com/me/picture?type=normal&method=GET&access_token="
+ Faceboo_Access_Token);
/**
* Background Async task to load user profile picture from url
* */privateclassLoadProfileImageextendsAsyncTask<String, Void, Bitmap> {
ImageView bmImage;
publicLoadProfileImage(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
Stringurldisplay= urls[0];
BitmapmIcon11=null;
try {
InputStreamin=newjava.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protectedvoidonPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
Solution 2:
have you successfully logged in Facebook ? if yes then
try {
JSONObject fbResObj = newJSONObject(fbUser
.getInnerJSONObject().toString());
String id = fbResObj.getString("id");
url = newURL("http://graph.facebook.com/" + id
+ "/picture?style=small");
Log.v(TAG, url.toString());
bmp = BitmapFactory.decodeStream(url
.openConnection().getInputStream());
} catch (Exception e) {
e.printStackTrace();
}
try this , where fbUser is the object of GraphUser which u get on executing GraphUserCallBack,
Solution 3:
privatevoidgetUserDetail() {
String fqlQuery = "SELECT name,uid,pic FROM user WHERE uid in (SELECT uid1 FROM friend WHERE uid1=me())";
Bundle _params = newBundle();
_params.putString("q", fqlQuery);
Session _session = Session.getActiveSession();
Request _request = newRequest(_session, "/fql", _params, HttpMethod.GET, newRequest.Callback() {
publicvoidonCompleted(Response response) {
GraphObject graphObject = response.getGraphObject();
if (graphObject != null) {
if (graphObject.getProperty("data") != null) {
try {
String _arry = graphObject.getProperty("data").toString();
JSONArray _jsonArray = newJSONArray(_arry);
if(_jsonArray.length()==1)
{
//here u will get your user's userId and Profile Picture and NameString _uid = _jsonObject.getString("uid");
String _Name = _jsonObject.getString("name");
String _ImagePath = _jsonObject.getString("pic");
}
}
} catch (JSONException ex) {
if (ex != null) {
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
}
}
});
Request.executeBatchAsync(_request);
}
Solution 4:
If you have Facebook id of user to get image use this link
https://graph.facebook.com/FACEBOOK_USER_ID/picture?type=large";
for small image use type = small
Post a Comment for "Not Able To Retrieve Profile Pic With Fb Login"