简体   繁体   English

检索Facebook Page墙上的帖子

[英]Retrieve Facebook Page wall posts

I want to include the FB Page wall into the website. 我想将FB Page墙包含在网站中。 For that purpose I need the access token, but on the FB I'm one of the admins not the owner. 为此,我需要访问令牌,但是在FB上,我是管理员之一,而不是所有者。

When I request an access token I get one of my profile not the profile that I´m administrating. 当我请求访问令牌时,我得到的是我的个人资料之一,而不是我正在管理的个人资料。 Can I get a token for that wall as admin and not owner ? 我可以以管理员身份而非所有者身份获得该墙的令牌吗?

如果您查看http://developers.facebook.com/docs/authentication/ ,则可以看到有一些以应用程序或页面身份登录的选项:这些选项应该可以为您提供所需的访问令牌。

From: http://developers.facebook.com/docs/reference/api/permissions/ 来自: http : //developers.facebook.com/docs/reference/api/permissions/

"Page access_token “页面access_token

An access_token used to manage a page. 用于管理页面的access_token。 This is used when you want to perform an operation acting as a Page. 当您要执行充当页面的操作时使用此功能。 This access token is retrieved by issuing an HTTP GET to /USER_ID/accounts or to /PAGE_ID?fields=access_token with the manage_pages permission. 通过向/ USER_ID / accounts或具有manage_pages权限的/ PAGE_ID?fields = access_token发出HTTP GET,可以检索此访问令牌。 Getting /USER_ID/accounts will return a list of Pages (including app profile pages) to which the user has administrative access in addition to an access_token for each Page. 获取/ USER_ID / accounts会返回用户具有管理访问权限的页面列表(包括应用程序配置文件页面),以及每个页面的access_token。 NOTE: After September 22, 2011, manage_pages permission will be required for all access to a user's pages via this connection, ie for both reading the user's pages and also retrieving access_tokens for those pages. 注意:2011年9月22日之后,通过此连接对用户页面的所有访问都将需要manage_pages权限,即,既要读取用户页面,又要检索这些页面的access_tokens。 See the documentation for the User object for more information." 有关更多信息,请参见User对象的文档。”

Facebook has extended their page object to make it easier to retrieve a "page" `access_token", what you need is: Facebook 扩展page对象,使其更易于检索“页面”`access_token“,您需要的是:

  • manage_pages & read_stream permissions manage_pages和read_stream 权限
  • the page_id page_id
  • Something like the code in my article : 类似于我文章中的代码:

PS: I'm using the PHP-SDK PS:我正在使用PHP-SDK

<?php
// This code is just a snippet of the example.php script
// from the PHP-SDK <http://github.com/facebook/php-sdk/blob/master/examples/example.php>
require '../src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => 'app_id',
  'secret' => 'app_secret',
));

// Get User ID
$user = $facebook->getUser();

if ($user) {
  try {
    $page_id = 'page_id';
    $page_info = $facebook->api("/$page_id?fields=access_token");
    if( !empty($page_info['access_token']) ) {
        $args = array(
            'access_token'  => $page_info['access_token']
        );
        $page_posts = $facebook->api("/$page_id/posts","get",$args);
    }
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,read_stream'));
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM