Facebook API: access denied (java.io.FilePermission read)
I'm trying to use jsp to create an image object from https://graph.facebook.com/marko/picture
The user first must log into facebook from my app before we try to access any of the files, however all of the profile images on facebook are publicly available. Anyway, I digress.
if I try to directly create a file based on this URL image string. It is instead a redirect to an image. Now, if I were to create an html image object (i.e. ) that works, but since Im trying to do this in jsp, it doesn't.
//This doesn't work
String strImgUrl = "https://graph.facebook.com/marko/picture";
File filProfileImage = new File(strImgUrl);
Image imgGraphic = (Image)ImageIO.read(filProfileImage);
It busts when Im trying to create the File object. How can I get around thi开发者_开发技巧s problem???
You can't create a java.io.File
that points to a network resource. You need to create a java.net.URL
instead. ImageIO
has an overloaded version of read
that works with a URL
, so you don't need any other changes besides that.
import java.net.URL;
import javax.imageio.ImageIO;
String strImgUrl = "https://graph.facebook.com/marko/picture";
URL urlProfileImage = new URL(strImgUrl);
Image imgGraphic = (Image)ImageIO.read(urlProfileImage);
精彩评论