作为主页而不是用户在 Facebook 墙上发帖

Post on a Facebook wall as Page, not as user(作为主页而不是用户在 Facebook 墙上发帖)
本文介绍了作为主页而不是用户在 Facebook 墙上发帖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

是否可以作为应用程序而不是用户在 Facebook 墙上发帖?据我所知,某个应用程序不是 Facebook 的有效用户,但有很多关于以主页身份而不是用户或应用程序发布的评论.

Is it possible to post on a Facebook wall as application and not as user? As far as I understand an application is not a valid user for Facebook, but there are numerous comments about posting as Page and not as User or Application.

如何使用 PHP Facebook API 来实现?

How can I do it using PHP Facebook API?

推荐答案

您需要 publish_stream,manage_pages 权限.代码类似于:

You need the publish_stream,manage_pages permissions. The code is something like:

<?php
// This code is just a snippet of the example.php script
// from the PHP-SDK <https://github.com/facebook/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'],
            'message'       => "I'm a Page!"
        );
        $post_id = $facebook->api("/$page_id/feed","post",$args);
    } else {
        $permissions = $facebook->api("/me/permissions");
        if( !array_key_exists('publish_stream', $permissions['data'][0]) ||
            !array_key_exists('manage_pages', $permissions['data'][0])) {
            // We don't have one of the permissions
            // Alert the admin or ask for the permission!
            header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages")) );
        }

    }
  } 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,publish_stream'));
}

// ... rest of your code
?>

我已经编写了关于此的深入教程:如何:在 Facebook 页面上作为页面而不是使用 PHP-SDK 的管理员用户发布

I've written and in-depth tutorial about this: How To: Post On Facebook Page As Page Not As Admin User Using PHP-SDK

这篇关于作为主页而不是用户在 Facebook 墙上发帖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Facebook Login with Strict Mode for Redirect URIs(使用重定向 URI 的严格模式登录 Facebook)
How to retrieve post ID for a post i#39;ve just made via the Facebook API(如何检索我刚刚通过 Facebook API 发布的帖子的帖子 ID)
Facebook PHP SDK logout(Facebook PHP SDK 注销)
Facebook SDK and Graph API Comment Deleting Error(Facebook SDK 和 Graph API 评论删除错误)
PHP amp; Facebook: facebook-debug a URL using CURL and Facebook debugger(PHP amp;Facebook: facebook-debug a URL using CURL and Facebook debugger)
Can#39;t delete photo via Facebook API?(无法通过 Facebook API 删除照片?)