gpt4 book ai didi

java - 如何使用访问 token 将数据发布到 Facebook 墙上

转载 作者:太空宇宙 更新时间:2023-11-04 08:04:48 27 4
gpt4 key购买 nike

Possible Duplicate:
Posting to a wall of a facebook user using the graph api

如何使用 Facebook API 生成的访问 token 在 Facebook 墙上发布数据。

最佳答案

使用 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();
}

}
}

关于java - 如何使用访问 token 将数据发布到 Facebook 墙上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12247064/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com