scribe 라이브러리를 사용하여 페이스 북에 이미지를 게시하려고합니다. 내 코드는 다음과 같습니다스크 라이브 라이브러리를 사용하여 Facebook에 이미지 게시
String apiKey = "MY_API_KEY";
String apiSecret = "MY_SECRET_KEY";
OAuthService service = new ServiceBuilder().provider(FacebookApi.class).apiKey(apiKey)
.apiSecret(apiSecret)
.callback("MY_CALL_BACK_URL")
.build();
Token accessToken = new Token("MY_ACCESS_TOKEN","");
OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL_STREAM);
request.addHeader("Content-Type", "text/html");
request.addBodyParameter("message", "Testing auto update.. Please ignore " + new DateTime());
//MultiPart for pic
Multipart mp = new MimeMultipart();
MimeBodyPart htmlPart = new MimeBodyPart();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
byte[] imagePayLoad = msgBody.getBytes("UTF-8"); //msgBody contains html string
byte[] mpByte = new byte[imagePayLoad.length];
htmlPart.setContent(msgBody, "text/html");
mp.addBodyPart(htmlPart);
//here I get the bytes[] of mp to out
mp.writeTo(out);
out.write(mpByte);
request.addPayload(mpByte);
} catch (Exception e) {
e.printStackTrace();
}
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Response");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
}
그러나 나는 또한 얻을
400
{"error":{"message":"(#100) Missing message or attachment","type":"OAuthException","code":100}}
나는 여러 부분, 텍스트 꺼내 경우 사람이 도와 주실 래요 ".. 난을 테스트 자동 업데이트를하시기 바랍니다 .."업데이트됩니다 페이스 북에. 사진과 바이트 []를 업로드해야합니다.
덕분에 내가 사용하고
:
는<dependency>
<groupId>org.scribe</groupId>
<artifactId>scribe</artifactId>
<version>1.3.0</version>
</dependency>
최신 버전은'1.3.1'입니다 (이것은 관련이 없지만 최신 안정 버전에서 항상 멋지다는 것에 유의하십시오). –