first version
This commit is contained in:
parent
73ae3cfb1a
commit
d936889921
|
@ -622,6 +622,21 @@
|
|||
<artifactId>bcpkix-jdk15on</artifactId>
|
||||
<version>1.58</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.http-client</groupId>
|
||||
<artifactId>google-http-client</artifactId>
|
||||
<version>1.23.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.http-client</groupId>
|
||||
<artifactId>google-http-client-jackson2</artifactId>
|
||||
<version>1.23.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.http-client</groupId>
|
||||
<artifactId>google-http-client-gson</artifactId>
|
||||
<version>1.23.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.googlehttpclientguide;
|
||||
|
||||
import com.google.api.client.http.HttpRequest;
|
||||
import com.google.api.client.http.HttpRequestFactory;
|
||||
import com.google.api.client.http.HttpRequestInitializer;
|
||||
import com.google.api.client.http.HttpResponseException;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
import com.google.api.client.json.JsonFactory;
|
||||
import com.google.api.client.json.JsonObjectParser;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Hugo
|
||||
*/
|
||||
public class DailyMotionExample {
|
||||
|
||||
static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
|
||||
static final JsonFactory JSON_FACTORY = new JacksonFactory();
|
||||
//static final JsonFactory JSON_FACTORY = new GsonFactory();
|
||||
|
||||
private static void run() throws Exception {
|
||||
HttpRequestFactory requestFactory
|
||||
= HTTP_TRANSPORT.createRequestFactory(
|
||||
new HttpRequestInitializer() {
|
||||
|
||||
public void initialize(HttpRequest request) {
|
||||
request.setParser(new JsonObjectParser(JSON_FACTORY));
|
||||
}
|
||||
});
|
||||
DailyMotionUrl url = new DailyMotionUrl("https://api.dailymotion.com/videos/");
|
||||
url.fields = "id,tags,title,url";
|
||||
HttpRequest request = requestFactory.buildGetRequest(url);
|
||||
VideoFeed videoFeed = request.execute().parseAs(VideoFeed.class);
|
||||
if (videoFeed.list.isEmpty()) {
|
||||
System.out.println("No videos found.");
|
||||
} else {
|
||||
if (videoFeed.hasMore) {
|
||||
System.out.print("First ");
|
||||
}
|
||||
System.out.println(videoFeed.list.size() + " videos found:");
|
||||
for (Video video : videoFeed.list) {
|
||||
System.out.println();
|
||||
System.out.println("-----------------------------------------------");
|
||||
System.out.println("ID: " + video.id);
|
||||
System.out.println("Title: " + video.title);
|
||||
System.out.println("Tags: " + video.tags);
|
||||
System.out.println("URL: " + video.url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
try {
|
||||
run();
|
||||
return;
|
||||
} catch (HttpResponseException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.googlehttpclientguide;
|
||||
|
||||
import com.google.api.client.http.GenericUrl;
|
||||
import com.google.api.client.util.Key;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Hugo
|
||||
*/
|
||||
public class DailyMotionUrl extends GenericUrl {
|
||||
|
||||
public DailyMotionUrl(String encodedUrl) {
|
||||
super(encodedUrl);
|
||||
}
|
||||
|
||||
@Key public String fields;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.googlehttpclientguide;
|
||||
|
||||
import com.google.api.client.util.Key;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Hugo
|
||||
*/
|
||||
public class Video {
|
||||
@Key public String id;
|
||||
|
||||
@Key public List<String> tags;
|
||||
|
||||
@Key public String title;
|
||||
|
||||
@Key public String url;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.googlehttpclientguide;
|
||||
|
||||
import com.google.api.client.util.Key;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Hugo
|
||||
*/
|
||||
public class VideoFeed {
|
||||
@Key public List<Video> list;
|
||||
|
||||
@Key("has_more")
|
||||
public boolean hasMore;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
# Properties file which configures the operation of the JDK logging facility.
|
||||
# The system will look for this config file to be specified as a system property:
|
||||
# -Djava.util.logging.config.file=${project_loc:dailymotion-simple-cmdline-sample}/logging.properties
|
||||
|
||||
# Set up the console handler (uncomment "level" to show more fine-grained messages)
|
||||
handlers = java.util.logging.ConsoleHandler
|
||||
java.util.logging.ConsoleHandler.level = ALL
|
||||
|
||||
# Set up logging of HTTP requests and responses (uncomment "level" to show)
|
||||
com.google.api.client.http.level = ALL
|
Loading…
Reference in New Issue