简体   繁体   English

如何使用Flickrj API将简单的ping测试发送到Flickr

[英]How to send a simple ping test to Flickr with Flickrj api

I am trying to send a single ping test to Flickr using flickrj. 我正在尝试使用flickrj将单个ping测试发送给Flickr。 I am following step by step the tutorial here 我在这里一步一步地学习本教程

https://github.com/callmeal/Flickr4Java https://github.com/callmeal/Flickr4Java

imported all the maven dependencies and everything and ended up with the following code: 导入了所有的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);

    }
}

I get the following error though: 我收到以下错误:

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)

What am I doing wrong? 我究竟做错了什么?

As per the documentation here , you would need a cast to 根据此处的文档,您需要强制转换为

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

The signature is.. 签名是..

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

You might have a conflict in imports, you are using com.flickr4java.flickr.collections.Collection while you most probably - as the echo method return type states - want to use java.util.Collection Class. 您可能在导入中存在冲突,正在使用com.flickr4java.flickr.collections.Collection,而您最有可能(因为echo方法返回类型说明)希望使用java.util.Collection类。 replace the line with: 将行替换为:

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

Your Code: 您的代码:

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

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM