Facebook App权限设置

时间:2015-11-12 00:49:21

标签: php facebook facebook-graph-api

我正试图用PHP发布我的Facebook页面。

我已经设置了Facebook API(版本4)并收集了我需要的所有数据,例如AppIdSecret KeyAccess Token,现在当我尝试在我的页面上发布时像这样:

require 'vendor/autoload.php';
define('FACEBOOK_SDK_V4_SRC_DIR', '/vendor/facebook/php-sdk-v4/src/Facebook/');

define("FACEBOOK_CONSUMER_KEY", "{myKey}");
define("FACEBOOK_CONSUMER_SECRET", "{mySecret}");
define("FACEBOOK_ACCESS_KEY", "{myToken}");

Facebook\FacebookSession::setDefaultApplication(FACEBOOK_CONSUMER_KEY, FACEBOOK_CONSUMER_SECRET);
$session = new Facebook\FacebookSession(FACEBOOK_ACCESS_KEY);

$message = array(
    "message" => "It works!",
    "link" => "http://www.google.de",
    //"picture" => "url to picture",
    //"name" => "Picture title",
    //"description" => "Description",
);

$response = ( new Facebook\FacebookRequest( $session, 'POST', '/{myPageId}/feed', $message ) )->execute()->getGraphObject();

echo $response->getProperty('id');

不幸的是,我执行以下错误:

PHP Fatal error:  Uncaught exception 'Facebook\FacebookPermissionException' with message '(#200) The user hasn't authorized the application to perform this action' in {myPath}/FacebookRequestException.php:128
Stack trace:
#0 {myPath}/FacebookRequest.php(280): Facebook\FacebookRequestException::create('{"error":{"mess...', Object(stdClass), 403)
#1 {myPath}/test.php(21): Facebook\FacebookRequest->execute()
#2 {main}
  thrown in {myPath}/FacebookRequestException.php on line 128

如何设置正常运行的Facebook应用程序?

1 个答案:

答案 0 :(得分:0)

您必须先执行登录流程才能授权您的应用。 https://developers.facebook.com/docs/php/howto/example_facebook_login/4.0.0