1
가능한 복제를 페이스 북의 벽에 데이터를 게시하는 방법 : 나는 페이스 북의 API에서 생성 된 액세스 토큰을 사용하여 페이스 북의 벽에 데이터를 게시 할 수있는 방법
Posting to a wall of a facebook user using the graph api액세스를 사용하여 토큰
.
가능한 복제를 페이스 북의 벽에 데이터를 게시하는 방법 : 나는 페이스 북의 API에서 생성 된 액세스 토큰을 사용하여 페이스 북의 벽에 데이터를 게시 할 수있는 방법
Posting to a wall of a facebook user using the graph api액세스를 사용하여 토큰
.
commons-http-client와 graph api를 사용하면 코드는 아래와 같이됩니다.
class WallPostService{
...
public makeWallPost(){
HttpClient client = null;
PostMethod method = null;
String urlStr = null;
String linkText = ""; //Facebook page name or alias
String linkURL = ""; //Facebook page URL
String response = null;
String accessToken = null;
try{
urlStr = "https://graph.facebook.com/$PROFILE_ID$/feed";
urlStr = urlStr.replace("$PROFILE_ID$", facebookId);
accessToken = getAccessToken();//[USER ACCESS TOKEN]
client = new HttpClient();
method = new PostMethod(urlStr);
method.setRequestHeader("pageEncoding", "UTF-8");
method.setRequestHeader("Content-Type", "text/html; charset=UTF-8");
method.addParameter("access_token", accessToken);
method.addParameter("message", "");
method.addParameter("link", "Link of wall post header");
method.addParameter("name", "Header of wall post");
method.addParameter("actions", "[{\"name\": \"" + linkText + "\" , \"link\": \"" + linkURL + "\"}]");
method.addParameter("caption", " ");
method.addParameter("description", "message body here");
method.addParameter("picture", "http://www.example.com/test.jpg");
client.executeMethod(method);
response = method.getResponseBodyAsString();
}
catch(Exception e){
}
finally{
method.releaseConnection();
}
}
}