【问题标题】:How to post the data on facebook wall using access token [duplicate]如何使用访问令牌在 facebook 墙上发布数据 [重复]
【发布时间】:2012-09-03 20:32:53
【问题描述】:

可能重复:
Posting to a wall of a facebook user using the graph api

如何使用从 facebook API 生成的访问令牌在 facebook 墙上发布数据。

【问题讨论】:

    标签: java facebook-graph-api


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-12-25
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多