我正在开发一款应该能够将照片上传到Facebook页面业务并在该照片中标记用户的应用。
我的问题是照片上传效果不错,但是当我尝试标记照片时,它在Facebook页面中不可见,照片信息显示标签存在,但带有“请求标签”消息。 / p>
这是我的代码总结:
FacebookType publishPhotoResponse = facebookClient.publish("me/photos", FacebookType.class,
BinaryAttachment.with("photo.jpg", readImagen(this.namePhoto)),
Parameter.with("message",this.message));
String photoId= publishPhotoResponse.getId();
try {
String relativePath = photoId + "/tags/" + userId;
StringBuilder sb = new StringBuilder("access_token=");
sb.append(URLEncoder.encode(token_user, "UTF-8"));
sb.append("&x=");
sb.append(URLEncoder.encode("50", "UTF-8"));
sb.append("&y=");
sb.append(URLEncoder.encode("50", "UTF-8"));
URL url = new URL("https://graph.facebook.com/"+relativePath);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("POST");
httpCon.setRequestProperty("Content-Type", "multipart/form-data");
httpCon.setRequestProperty("Content-Length", "" + sb.toString().length());
OutputStreamWriter out = new OutputStreamWriter( httpCon.getOutputStream());
out.write(sb.toString());
out.flush();
System.out.println(httpCon.getResponseCode());
System.out.println(httpCon.getResponseMessage());
System.out.println(sb.toString());
System.out.println(out.getEncoding());
System.out.println(out.toString());
System.out.println("url : "+url);
} catch (IOException ex) {
System.out.println(ex);
}
在控制台中显示此信息:
500
Internal Server Error
access_token=XXXXXXXXXX....XXXX..X&x=50&y=50
UTF8
java.io.OutputStreamWriter@1eb13dc
url : https://graph.facebook.com/XXXXXXXXXXXXX/tags/XXXXXXXXXXXXX
我不知道是什么问题,根据500错误似乎错误不是我的,但也许我没有正确地做到这一点。有人能帮助我吗?