Facebook PHP SDK-发布到Facebook页面但创建帖子时出现错误 [英] Facebook PHP SDK - Getting error when posting to facebook page but post is created

查看:209
本文介绍了Facebook PHP SDK-发布到Facebook页面但创建帖子时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么,但是当我尝试发布到我创建的Facebook页面时,出现以下错误:

Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message 'Unsupported post request.

这是我当前拥有的代码:

<?php
session_start();

require 'vendor/autoload.php';


use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphUser;


FacebookSession::setDefaultApplication('my-app-id', 'my-app-secret');

$session = new FacebookSession('my-access-token');

if($session){

    $request = new FacebookRequest($session, 'GET', '/me/accounts?fields=name,access_token,perms');
    $pageList = $request->execute()->getGraphObject()->asArray();
    $token = $pageList['data'][0]->access_token;

    $request2 = new FacebookRequest(
        $session,
        'POST',
        '/my-page-id/feed',
        array (
          'access_token' => $token,
          'name' => 'MySQL: Why My?',
          'caption' => 'MySQL: Why My?',
          'link' => 'http://www.vertabelo.com/blog/mysql-history',
          'message' => 'MySQL: Why My?',
        )
    );

    $response2 = $request2->execute();
    print_r($response2);

}

返回错误,但在我检查时该帖子实际上已发布在Facebook页面中.我在这里做错什么了吗?

我尝试过的另一种选择是从另一个页面加载中获取页面访问令牌,然后在new FacebookSession调用中设置它,而不是在我的配置文件中访问令牌.然后,我在创建新帖子的请求中省略了access_token.它还返回一个错误,但该帖子也在页面上创建.有什么想法吗?

解决方案

这与POSTlink字段连接到/{page-id}/feed端点特别相关.

当您的应用处于开发模式时,将返回此错误.如果您使该应用程序正常运行,它应该可以正常工作.

很确定这不是预期的行为,所以我提交了错误报告.

I don't know why but I get the following error when I'm trying to post to a facebook page that I've created:

Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message 'Unsupported post request.

Here's the code that I currently have:

<?php
session_start();

require 'vendor/autoload.php';


use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphUser;


FacebookSession::setDefaultApplication('my-app-id', 'my-app-secret');

$session = new FacebookSession('my-access-token');

if($session){

    $request = new FacebookRequest($session, 'GET', '/me/accounts?fields=name,access_token,perms');
    $pageList = $request->execute()->getGraphObject()->asArray();
    $token = $pageList['data'][0]->access_token;

    $request2 = new FacebookRequest(
        $session,
        'POST',
        '/my-page-id/feed',
        array (
          'access_token' => $token,
          'name' => 'MySQL: Why My?',
          'caption' => 'MySQL: Why My?',
          'link' => 'http://www.vertabelo.com/blog/mysql-history',
          'message' => 'MySQL: Why My?',
        )
    );

    $response2 = $request2->execute();
    print_r($response2);

}

An error is returned but the post is actually posted in the facebook page when I check. Am I doing something wrong here?

Another alternative that I tried is to get the page access token from another page load and then set it on the new FacebookSession call instead of the access token of my profile. Then I omit the access_token in the request for creating a new post. It also returns an error but the post is also created on the page. Any ideas?

解决方案

This is specifically related to POSTing the link field to the /{page-id}/feed endpoint.

This error is returned when your app is in development mode. If you make the app live, it should work.

Pretty sure this is not the intended behavior, so I submitted a bug report.

这篇关于Facebook PHP SDK-发布到Facebook页面但创建帖子时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆