首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用java从flicker中获取公共数据和图片?

如何使用java从flicker中获取公共数据和图片?
EN

Stack Overflow用户
提问于 2015-04-27 12:33:22
回答 1查看 903关注 0票数 0

我正在尝试使用Flickr提供的API密钥和密钥来获取flickr数据。我已经为它写了一个java代码。

代码语言:javascript
复制
`package com.flickr.project;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import com.aetrion.flickr.Flickr;
import com.aetrion.flickr.FlickrException;
import com.aetrion.flickr.REST;
import com.aetrion.flickr.auth.Permission;
import com.aetrion.flickr.photos.SearchParameters;
import com.aetrion.flickr.photos.PhotoList;
import com.aetrion.flickr.photos.PhotosInterface;
import com.aetrion.flickr.photos.Photo;
import com.flickr4java.flickr.Auth;
import com.flickr4java.flickr.RequestContext;
public class SampleProgram{

    public static void main(String[] args) {
        try {
            searchImages();

        } catch (Exception e) {

            e.printStackTrace();
        }
    }



public static  void searchImages() {
   //  Search photos with tag keywords and get result
 try{
         //Set api key
        String key="";
        String svr="www.flickr.com";
        String secret="";

        RequestContext requestContext = RequestContext.getRequestContext();
        Auth auth = new Auth();
        auth.setPermission(Permission.READ);
        auth.setToken("");
        auth.setTokenSecret("");
        requestContext.setAuth(auth);
        REST rest=new REST();
        rest.setHost(svr);

        //initialize Flickr object with key and rest
        Flickr flickr=new Flickr(key,secret,rest);
        Flickr.debugRequest = false;
        Flickr.debugStream = false;
        Flickr.debugStream=false;

        //initialize SearchParameter object, this object stores the search keyword
        SearchParameters searchParams=new SearchParameters();
        searchParams.setSort(SearchParameters.INTERESTINGNESS_DESC);
        //Create tag keyword array
        String[] tags=new String[]{"Dog","Doberman"};
        searchParams.setTags(tags);

        //Initialize PhotosInterface object
        PhotosInterface photosInterface=flickr.getPhotosInterface();

        //Execute search with entered tags
       // PhotoList photoList=null;
        PhotoList photoList=photosInterface.search(searchParams,20,1);
        System.out.println("here");
        //get search result and fetch the photo object and get small square imag's url
        if(photoList!=null){
           //Get search result and check the size of photo result
           for(int i=0;i<photoList.size();i++){
              //get photo object
              Photo photo=(Photo)photoList.get(i);
              //Get small square url photo
              StringBuffer strBuf=new StringBuffer();
              strBuf.append("<a href=\"\">");
              strBuf.append("<img border=\"0\" src=\""+photo.getSmallSquareUrl()+"\">");
              strBuf.append("</a>\n");
            //  ....
           }
        }
}catch(Exception e){
    e.printStackTrace();
}
    }

public void  userAuthentication(){
    /*InputStream in = null;
    try {
        in = getClass().getResourceAsStream("/setup.properties");
      //  properties = new Properties();
      //  properties.load(in);
    } finally {
        IOUtilities.close(in);
    }
    f = new Flickr(properties.getProperty("apiKey"), properties.getProperty("secret"), new REST());
    requestContext = RequestContext.getRequestContext();
    Auth auth = new Auth();
    auth.setPermission(Permission.READ);
    auth.setToken(properties.getProperty("token"));
    auth.setTokenSecret(properties.getProperty("tokensecret"));
    requestContext.setAuth(auth);
    Flickr.debugRequest = false;
    Flickr.debugStream = false;*/
}
    }   `

我需要使用我在程序中提到的关键字从flickr获取所有数据,包括图像。

EN

回答 1

Stack Overflow用户

发布于 2015-04-27 12:56:10

从外观上看,Photo有如下几种方法:

"getSmallSquareAsInputStream“-返回一个输入流,可用于获取图像数据。

有关照片类的完整API列表,请访问here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29887258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档