Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Facebook4j api从页面获取帖子_Java_Facebook_Facebook Graph Api_Facebook4j - Fatal编程技术网

Java 使用Facebook4j api从页面获取帖子

Java 使用Facebook4j api从页面获取帖子,java,facebook,facebook-graph-api,facebook4j,Java,Facebook,Facebook Graph Api,Facebook4j,我想知道是否有办法使用Facebook4J API从facebook页面获取所有(甚至最近)帖子 我知道可以从用户的墙或提要获取所有帖子,但在API或文档中找不到任何显示如何从页面获取帖子的内容 看一看,事实上似乎有一组与页面相关的方法,但单击其中任何一个都会刷新页面,让我觉得它们可能是计划好的,但尚未实现 我知道使用graph API从页面获取帖子是可能的,但如果可能的话,我宁愿使用Facebook4j 任何意见都将不胜感激 自版本2.0以来,Facebook4J支持页面API。 你可以通过f

我想知道是否有办法使用Facebook4J API从facebook页面获取所有(甚至最近)帖子

我知道可以从用户的墙或提要获取所有帖子,但在API或文档中找不到任何显示如何从页面获取帖子的内容

看一看,事实上似乎有一组与页面相关的方法,但单击其中任何一个都会刷新页面,让我觉得它们可能是计划好的,但尚未实现

我知道使用graph API从页面获取帖子是可能的,但如果可能的话,我宁愿使用Facebook4j


任何意见都将不胜感激

自版本2.0以来,Facebook4J支持页面API。
你可以通过facebook#getFeed(page#u ID)从facebook页面获取帖子。 例如:

ResponseList feed=facebook.getFeed(“eclipse.org”);

javadoc:

以下是您的问题的一个简单示例: 请注意,您可以从中获取访问令牌和页面ID 在代码中使用以下id:

import facebook4j.Comment;
import facebook4j.Facebook;
import facebook4j.FacebookException;
import facebook4j.FacebookFactory;
import facebook4j.PagableList;
import facebook4j.Post;
import facebook4j.Reading;
import facebook4j.ResponseList;
import facebook4j.auth.AccessToken;

public class PostsFromPageExtractor {

/**
 * A simple Facebook4J client which
 * illustrates how to access group feeds / posts / comments.
 * 
 * @param args
 * @throws FacebookException 
 */
public static void main(String[] args) throws FacebookException {

    // Generate facebook instance.
    Facebook facebook = new FacebookFactory().getInstance();
    // Use default values for oauth app id.
    facebook.setOAuthAppId("", "");
    // Get an access token from: 
    // https://developers.facebook.com/tools/explorer
    // Copy and paste it below.
    String accessTokenString = "PASTE_YOUR_ACCESS_TOKEN_HERE";
    AccessToken at = new AccessToken(accessTokenString);
    // Set access token.
    facebook.setOAuthAccessToken(at);

    // We're done.
    // Access group feeds.
    // You can get the group ID from:
    // https://developers.facebook.com/tools/explorer

    // Set limit to 25 feeds.
    ResponseList<Post> feeds = facebook.getFeed("187446750783",
            new Reading().limit(25));

        // For all 25 feeds...
        for (int i = 0; i < feeds.size(); i++) {
            // Get post.
            Post post = feeds.get(i);
            // Get (string) message.
            String message = post.getMessage();
                            // Print out the message.
            System.out.println(message);

            // Get more stuff...
            PagableList<Comment> comments = post.getComments();
            String date = post.getCreatedTime().toString();
            String name = post.getFrom().getName();
            String id = post.getId();
        }           
    }
}
导入facebook4j.注释;
导入facebook4j.Facebook;
导入facebook4j.FacebookException;
导入facebook4j.FacebookFactory;
导入facebook4j.PagableList;
导入facebook4j.Post;
导入facebook4j.读取;
导入facebook4j.ResponseList;
导入facebook4j.auth.AccessToken;
公共类PostsFromPageExtractor{
/**
*一个简单的Facebook4J客户端
*说明如何访问组提要/帖子/评论。
* 
*@param args
*@FacebookException
*/
公共静态void main(字符串[]args)引发FacebookException{
//生成facebook实例。
Facebook=新建FacebookFactory().getInstance();
//使用oauth应用程序id的默认值。
setOAuthAppId(“,”);
//从以下位置获取访问令牌:
// https://developers.facebook.com/tools/explorer
//复制并粘贴到下面。
String accessTokenString=“在此处粘贴您的访问令牌”;
AccessToken at=新的AccessToken(accessTokenString);
//设置访问令牌。
setOAuthAccessToken(at);
//我们结束了。
//访问组源。
//您可以从以下位置获取组ID:
// https://developers.facebook.com/tools/explorer
//将限制设置为25个提要。
ResponseList feed=facebook.getFeed(“187446750783”,
新读数()限值(25);
//对于所有25个提要。。。
对于(int i=0;i
如何在getFeed(“187446750783”)中获取页面id?但如果我们在我们的数据库中硬编码appId和appSecret,则运行该代码的人将可以访问我自己的fb页面。是否有其他方法可以通过不硬编码上述值来获取appId、appSecret和accessToken。上述代码不起作用,它会产生facebookexception:“graph.facebook.com FacebookException{statusCode=-1,errorType='null',errorMessage='null',errorCode=-1,errorSubcode=-1,version=2.4.5}”如何从页面获取所有帖子而无需访问者帖子?我只需要页面本身的公共帖子。目前我调用getFeed()方法,它还将访问者帖子返回到该页面。
import facebook4j.Comment;
import facebook4j.Facebook;
import facebook4j.FacebookException;
import facebook4j.FacebookFactory;
import facebook4j.PagableList;
import facebook4j.Post;
import facebook4j.Reading;
import facebook4j.ResponseList;
import facebook4j.auth.AccessToken;

public class PostsFromPageExtractor {

/**
 * A simple Facebook4J client which
 * illustrates how to access group feeds / posts / comments.
 * 
 * @param args
 * @throws FacebookException 
 */
public static void main(String[] args) throws FacebookException {

    // Generate facebook instance.
    Facebook facebook = new FacebookFactory().getInstance();
    // Use default values for oauth app id.
    facebook.setOAuthAppId("", "");
    // Get an access token from: 
    // https://developers.facebook.com/tools/explorer
    // Copy and paste it below.
    String accessTokenString = "PASTE_YOUR_ACCESS_TOKEN_HERE";
    AccessToken at = new AccessToken(accessTokenString);
    // Set access token.
    facebook.setOAuthAccessToken(at);

    // We're done.
    // Access group feeds.
    // You can get the group ID from:
    // https://developers.facebook.com/tools/explorer

    // Set limit to 25 feeds.
    ResponseList<Post> feeds = facebook.getFeed("187446750783",
            new Reading().limit(25));

        // For all 25 feeds...
        for (int i = 0; i < feeds.size(); i++) {
            // Get post.
            Post post = feeds.get(i);
            // Get (string) message.
            String message = post.getMessage();
                            // Print out the message.
            System.out.println(message);

            // Get more stuff...
            PagableList<Comment> comments = post.getComments();
            String date = post.getCreatedTime().toString();
            String name = post.getFrom().getName();
            String id = post.getId();
        }           
    }
}