如何通过Flickrj Api访问私人照片? [英] How to access private photos through Flickrj Api?
问题描述
我正在通过电话进行身份验证,以通过Flickr API访问照片.但是我只会得到我的公开照片,而不会得到任何私人照片.
I'm making an authenticated call to access photos through Flickr API. But I am only getting my public photos but not any private photos.
下面是我正在使用的代码,
Given below is the code I'm using,
Flickr f;
RequestContext requestContext;
String frob = "";
String token = "";
DocumentBuilder xmlParser = null;
public void getImages() throws ParserConfigurationException, IOException, SAXException, FlickrException, URISyntaxException, NoSuchAlgorithmException
{
DocumentBuilderFactory dcb = DocumentBuilderFactory.newInstance();
try {
this.xmlParser = dcb.newDocumentBuilder();
} catch (ParserConfigurationException ex) {
ex.printStackTrace();
}
f = new Flickr("199d038ad88f6c6c377a4ab2341fb60f","4583b2386d3d6439",new REST()) ;
Flickr.debugStream = false;
requestContext = RequestContext.getRequestContext();
AuthInterface authInterface = f.getAuthInterface();
//PeopleInterface peopleInterface = f.getPeopleInterface();
try {
frob = authInterface.getFrob();
} catch (FlickrException e) {
e.printStackTrace();
}
System.out.println("frob: " + frob);
java.net.URL url =authInterface.buildAuthenticationUrl(Permission.READ, frob);
System.out.println(url.toExternalForm());
Desktop desktop = Desktop.getDesktop();
desktop.browse(url.toURI());
// Get the response
Auth auth = null ;
String aLine = "";
while(aLine.equals(""))
{
java.io.DataInputStream in = new java.io.DataInputStream(System.in);
aLine = in.readLine();
}
auth =authInterface.getToken(frob);
System.out.println("auth = "+auth);
requestContext = RequestContext.getRequestContext();
requestContext.setAuth(auth);
f.setAuth(auth);
UrlsInterface urlsInterface = f.getUrlsInterface();
PhotosInterface photosInterface = f.getPhotosInterface();
SearchParameters searchParams=new SearchParameters();
searchParams.setSort(SearchParameters.INTERESTINGNESS_DESC);
//Execute search with entered tags
searchParams.setUserId(auth.getUser().getId());
PhotoList photoList=photosInterface.search(searchParams, 10,1);
if(photoList!=null){
//Get search result and check the size of photo result
for(int i=0;i<photoList.size();i++){
Photo photo=(Photo)photoList.get(i);
System.out.println(photo.getSmallSquareUrl());
}
}
推荐答案
我设法采用另一种方法来解决此问题.
I managed to solve this problem by following a different approach.
这就是我解决这个问题的方式.我没有使用GET方法,而是在photoSetsInterface(photoSetsInterface.getList(auth.getUser().getId()).getPhotosets())中使用了getList方法.对于此方法,您可以将auth_token用作输入参数.因此,它为您提供了所有照片集.然后,我拍摄了每个照片集,并在所有隐私级别下检索了图像.
This is how i solved this. Instead of using the GET method I used the getList method in photoSetsInterface (photoSetsInterface.getList(auth.getUser().getId()).getPhotosets()) .For this method you can pass the auth_token as an input parameter. Therefore it gives you all the photo sets. Then I took each photoset and retrived images under all privacy levels.
然后,可以使用PhotosInterface中的getNotInSet方法拍摄不在集合中的所有照片.无论隐私级别如何,getNotInSet方法都会返回所有不在集合中的照片.
And then you can take all the photos that are not in a set by using the getNotInSet method in PhotosInterface. getNotInSet method returns all the photos not in a set regardless of the privacy level.
您可以在我的中找到示例代码博客.
这篇关于如何通过Flickrj Api访问私人照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!