简体   繁体   中英

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. I am following step by step the tutorial here

https://github.com/callmeal/Flickr4Java

imported all the maven dependencies and everything and ended up with the following 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();
    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. 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);

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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