如何使用 Flickrj 向 Flickr 发送简单的 ping 测试 api

How to send a simple ping test to Flickr with Flickrj api

我正在尝试使用 flickrj 向 Flickr 发送一个 ping 测试。我正在逐步按照此处的教程进行操作

https://github.com/callmeal/Flickr4Java

导入了所有 Maven 依赖项和所有内容,并以以下代码结束:

import java.util.Collections;

import com.flickr4java.flickr.Flickr;
import com.flickr4java.flickr.REST;
import com.flickr4java.flickr.collections.Collection;

import com.flickr4java.flickr.test.TestInterface;

public class hello {
    public static void main(String args[]){


    String apiKey = "3f7046fe0897516df587cc3e6226f878";
    String sharedSecret = "9d0ceef5f2f3040f";
    Flickr f = new Flickr(apiKey, sharedSecret, new REST());
    TestInterface testInterface = f.getTestInterface();
    Collection results = testInterface.echo(Collections.EMPTY_MAP);

    }
}

虽然我收到以下错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Type mismatch: cannot convert from Collection<Element> to Collection

    at hello.main(hello.java:18)

我做错了什么?

根据文档 here,您需要强制转换为

Collection<Element> results = testInterface.echo(Collections.EMPTY_MAP);

签名是..

public Collection<Element> echo(Map<String, String> params) throws  FlickrException {
....
    return response.getPayloadCollection();
}

您可能在导入中存在冲突,您正在使用 com.flickr4java.flickr.collections.Collection 而您很可能 - 作为 echo 方法 return 类型状态 - 想要使用 java.util.Collection Class。 将行替换为:

java.util.Collection<Element> results = testInterface.echo(Collections.EMPTY_MAP);

您的代码:

import java.util.Collections;

import com.flickr4java.flickr.Flickr;
import com.flickr4java.flickr.REST;
import com.flickr4java.flickr.collections.Collection;

import com.flickr4java.flickr.test.TestInterface;

public class hello {
    public static void main(String args[]){


    String apiKey = "3f7046fe0897516df587cc3e6226f878";
    String sharedSecret = "9d0ceef5f2f3040f";
    Flickr f = new Flickr(apiKey, sharedSecret, new REST());
    TestInterface testInterface = f.getTestInterface();
    java.util.Collection<Element> results = testInterface.echo(Collections.EMPTY_MAP);

    }
}