I am using the Twitter4J API in Java to retrieve the profile image for a Twitter user whose logged in. The command is something like :
twitter.getProfileImage(twitter.getScreenName(), Imagesize);
What is the image size? How can I display the ProfileImage object in a label for example?
ok, the answer is :
Assume that the Twitter object is twitter
1 - get the user from the twitter object
User user = twitter.showUser(twitter.getid());
2 - get the profile image URL
URL url = user.getProfileImageURL();
3 - create Image icon
ImageIcon img = new ImageIcon(url);
4 - set the JLabel icon to be the ImageIcon
Jlabel1.setIcon(img);
Take a look at the example code.
https://github.com/yusuke/twitter4j/blob/master/twitter4j-examples/src/main/java/twitter4j/examples/user/GetProfileImage.java
You can pass either ProfileImage.MINI, ProfileImage.NORMAL or ProfileImage.BIGGER
Related
I am working with Facebook Share Dialog When i call the Facebook Sharedialog it always get the data from href.
Code snippet -
this.facebook.showDialog({
method: 'share',
href: 'https://google.com',
name: 'Name',
picture: 'https://www.w3schools.com/w3css/img_forest.jpg',
description: 'Description'
});
See changelog v2.9 of the Graph API: https://developers.facebook.com/docs/graph-api/changelog/version2.9
90-Day Breaking Changes
The following fields are deprecated for edges and dialogs that allow
attaching links to posts:
caption
description
name
picture
thumbnail
This was changed to prevent users from using wrong OG Tags if they do not own the URL. Use OG Tags on the shared URL instead: https://developers.facebook.com/docs/sharing/webmasters/
Here is my code to display profile picture using gravatar.
ParseUser user = mUsers.get(position);
String email = user.getEmail().toLowerCase();
if (email.equals("")) {
holder.userImageView.setImageResource(R.drawable.avatar_empty);
} else {
String hash = MD5Util.md5Hex(email);
String gravatarUrl = "http://www.gravatar.com/avatar/" + hash + "?s=204&d=404";
Picasso.with(mContext).load(gravatarUrl)
.placeholder(R.drawable.avatar_empty)
.into(holder.userImageView);
}
But it is not showing even my profile picture and loads empty drawable.
You used a bunch of fake emails to populate your friend list, if so, gravatar won't be able to find images for those fake emails. So gravatar will return a 404, and your code will use the default "avatar_empty" image in the drawable folder.
A quick way to test to see if gravatar is working is to change the &d=404 to &d=monsterid and create a friend with a fake email "SDFSDSF#DSFSsdfsFSFSssf.com"
That friend will have an gravatar cartoon image.
Also you can try put http://www.gravatar.com/avatar/edb1260aa6f7f77688deee83e0a088f7?s=204&d=monsterid in your gravatarUrl. It will show picture.
Hope this helps someone , this is the code i used.
get library from:- https://github.com/tkeunebr/gravatar-android (you will get the .jar,, add it to lib)
Code for loading gravatar:
String gravatarUrl = Gravatar.init().with(user.email).size(100).build();
Picasso.with(mContext)
.load(gravatarUrl)
.into((ImageView) convertView.findViewById(R.id.user_avatar));
And if you want to set a default image in case of there is no gravatar set for the email(to override the default gravatar) then use:
String gravatarUrl = Gravatar.init().with(user.email).defaultImage(defaultImageUrl).size(100).build();
Hope this helps someone.
It's weird, but till yesterday i was able to get the gplus user's image in my app but today it's just not coming. Nothing simply blank. And just appears at some time..
I have been using the urls specified in Getting Google+ profile picture url with user_id but these all seem invalid and gives 404 Error.
https://plus.google.com/s2/photos/profile/116018066779980863044?sz=100
If anybody could help me out why this weird behaviour. The Profile pic appears seldom. But mostly it's blank.
The image URL you were using was never a public API and so there was no guarantee it would continue to work. The recommended practice going forward is to use the people.get API method to get the profile => image => url value instead. That URL could stop working if the user changes their avatar so you might want to fetch the actual image and cache it on your own servers.
I think the Image url has been updated.
Inorder to get that, we can use the PlusClient objects methods:
imageURL = mPlusClient.getCurrentPerson().getImage().getUrl()
{Returns a String - Image Url as String}
imageURL = mPlusClient.getCurrentPerson().getImage()
{Returns an instance of Image object}
I used graph API Json Response of Facebook Wall Post Images and display in my APP i successfully got it. But the wall images look very Blur how to resolve? i used this code for get wall picture
URL url=new URL(hashMap.get("picture_url"));
bitmap=BitmapFactory.decodeStream(url.openConnection().getInputStream());
((ImageView)view.findViewById(R.id.imageView_FullImage)).setImageBitmap(bitmap)
The Facebook Graph API as well as the FQL data set always returns the Picture URL of a thumbnail. If you look at the URL it returns, it will have one of these ending (right before the image extension .jpg, .png, etc) _t., _a.. For example, if the URL is to a JPG file, it could have an ending _t.jpg
The idea is to swap the ending and choose a normal size for the image that is returned. To do this, use the code below that will replace the endings with the one for normal sized images (that should have the _n.)
By the way, I don't think the tag you are looking for is picture_url. It should be just picture. But regardless, get the source URL as shown below, replace the endings and then pass it to the this line in your code:
// THIS SHOULD BE AFTER THE if....else code block
bitmap=BitmapFactory.decodeStream(url.openConnection().getInputStream());
CODE TO REPLACE THE VARIOUS THUMBNAIL IMAGES: By the way, this is production code and works perfect.
String PICTURE_URL;
String getPicture = JOFeeds.getString("picture");
if (getPicture.contains("_t.")) {
PICTURE_URL = getPicture.replaceAll("_t.", "_n.");
} else if (getPicture.contains("_a.")) {
PICTURE_URL = getPicture.replaceAll("_a.", "_n.");
} else if (getPicture.contains("_s.")) {
PICTURE_URL = getPicture.replaceAll("_s.", "_n.");
} else if (getPicture.contains("_q.")) {
PICTURE_URL = getPicture.replaceAll("_q.", "_n.");
}
Note: However, in some cases, like a Video preview or a Link preview, it will not always have a bigger image available. Nothing much you can do about it nor can Facebook I suspect. These typically come from posts that are shared by users from other websites.
I'm trying to retrieve the currently-logged-in user's avatar image so that I can save it on my server and use it later in my application.
How would I go about getting the image directly?
Try this:
(replace USER_ID with alias or user ID...)
set source as https://graph.facebook.com/USER_ID/picture
for example large icon of a Page ID 149926629437 is:
http://graph.facebook.com/149926629437/picture?type=large
<img src="http://graph.facebook.com/149926629437/picture?type=large"/>
more info (specify size etc...):
http://developers.facebook.com/docs/reference/api/
part Pictures
(I also userd the aQuery (android query) to cache images...
aq.id( holder.image).image("https://graph.facebook.com/" + USER_ID + "/picture?type=normal");
http://code.google.com/p/android-query/
It seems working fine...
)
Can't say much about this, but you might want to try the facebook android sdk here ->https://github.com/facebook/facebook-android-sdk . Good luck :)
If you want a higher quality profile picture try:
https://graph.facebook.com/{ID}?fields=picture.height(2048)
And then retrieve the response.picture.data.url