我正在开发一个应用程序,它应该能够将照片上传到 Facebook 页面业务并在该照片中标记用户。
我的问题是照片上传得很好,但是当我尝试标记照片时,它在 Facebook 页面中不可见,在照片的信息中显示该标签存在但带有“请求的标签”消息。
这是我总结的代码:
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错误似乎不是我的错误,但也许我没有正确执行。有人可以帮助我吗?