English 中文(简体)
使用新泽西州Greaph API上传照片
原标题:Upload a photo via Graph API using Jersey

I have a Java application and i try to upload a photo to Facebook via graph api with Jersey. Until now everything works fine with Jersey I can publish messages etc.

I searched hours to find an example how to do it. The best tutorial I found was this one:

http://neopatel.blogspot.de/2011/04/jersey-posting-multiple-data.html" rel="no follow" >http://neopatel.blogspot.de/2011/04/jersey-posting-multipart-data.html

我只知道我要使用多部分/格式数据。

是否有人有例子或知道必须这样做?

最佳回答

您是否尝试使用"http://jersey.java.net/nonav/apidocs/1.8/contribs/jersey-mulpart/index.html" rel=“nofollow”>jersey-mulpart 套件?

您为文件创建了 < code> FormDataMultiPart ,为信件创建了 < code> FileDataBodyPart ,为信件创建了 < code> FormDataBodyPart ,为信件创建了 < fileDataBodyPart ,为信件创建了 < folleDataBodyPart > 和访问用户创建了 < formDataBodyPart 。

问题回答

这是我的解决方案

String url = "https://graph.facebook.com/me/photos";
File file = new File("path");

ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);
Client client = Client.create(cc);

WebResource webResource = client.resource(url); 
FormDataMultiPart fdmp = new FormDataMultiPart(); 

fdmp.bodyPart(new FileDataBodyPart("source", file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
fdmp.bodyPart(new FormDataBodyPart("message", "YAY I did it!"));
fdmp.bodyPart(new FormDataBodyPart("access_token", accessToken));

ClientResponse response = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, fdmp); 
String string = response.getEntity(String.class); 




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签