gpt4 book ai didi

private - 如何通过Flickrj Api访问私有(private)照片?

转载 作者:行者123 更新时间:2023-12-02 16:39:01 26 4
gpt4 key购买 nike

我正在通过 Flickr API 进行经过身份验证的调用来访问照片。但我只得到我的公开照片,而没有任何私有(private)照片。

下面给出的是我正在使用的代码,

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());

}

}

最佳答案

可以通过编辑 flickrj 来访问私有(private)数据。

我在com.aetrion.flickr.photos.PhotosInterface中添加了auth_token参数:

public PhotoList search(SearchParameters params, int perPage, int page)
throws IOException, SAXException, FlickrException {
PhotoList photos = new PhotoList();

List parameters = new ArrayList();
parameters.add(new Parameter("method", METHOD_SEARCH));
parameters.add(new Parameter("api_key", apiKey));

parameters.addAll(params.getAsParameters());


if (perPage > 0) {
parameters.add(new Parameter("per_page", "" + perPage));
}
if (page > 0) {
parameters.add(new Parameter("page", "" + page));
}
//
String token = RequestContext.getRequestContext().getAuth().getToken();
if (token != null)
parameters.add(
new Parameter(
"auth_token",
RequestContext.getRequestContext().getAuth().getToken()
)
);
//
parameters.add(
new Parameter(
"api_sig",
AuthUtilities.getSignature(sharedSecret, parameters)
)
);

Response response = transport.get(transport.getPath(), parameters);

通过此更改,我能够获取我的私有(private)照片。

flickr api 文档说,“每个经过身份验证的调用都需要 auth_token api_sig 参数“..但缺少了。

我从那里得到了这个想法:link text并使用 servlet 访问 flickr。

关于private - 如何通过Flickrj Api访问私有(private)照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3289552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com