尝试通过 AMFPHP 在 facebook 中发帖时出现问题

发布于 2024-09-28 00:36:57 字数 982 浏览 1 评论 0原文

我正在使用 AMFPHP,并在 php 中编写了一个小函数,以便在调用时在 facebook 中发布:

function postear($pregunta,$winoption,$loseoption) {
    require_once("../../facebook.php");
    Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;

    $facebook = new Facebook(array(
        'appId'  => 'xxxxxxxxxxxxx',
        'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        'cookie' => false
    ));

    $session = $facebook->getSession();
    $token = $session['access_token'];

    //echo "Post successful !"; 
    $facebook->api( '/me/feed', 'POST', array ( 'message' => '','link' => 'http://www.facebook.com/apps/myapp','name' => 'dummy name'));
}

我收到此错误:

message = "faultCode:AMFPHP_RUNTIME_ERROR failureString:'必须使用活动访问令牌来查询有关当前信息的信息用户。'

我对 Facebook 的图 api 不太熟悉,有点困惑,因为有时我可以通过调用我的函数来发布正确性,而其他时候则给我上面的错误,也许我需要以某种方式将令牌传递给我的发布调用?我的调用中“cookie”参数的目的是让我登录 Facebook?

另外,访问令牌是唯一的?或者每次有人登录应用程序时都会生成不同的令牌?

感谢您的指导并感谢您的帮助 。帮助。

I'm using AMFPHP, and wrote a small function in php to post in facebook whenever it's called:

function postear($pregunta,$winoption,$loseoption) {
    require_once("../../facebook.php");
    Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;

    $facebook = new Facebook(array(
        'appId'  => 'xxxxxxxxxxxxx',
        'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        'cookie' => false
    ));

    $session = $facebook->getSession();
    $token = $session['access_token'];

    //echo "Post successful !"; 
    $facebook->api( '/me/feed', 'POST', array ( 'message' => '','link' => 'http://www.facebook.com/apps/myapp','name' => 'dummy name'));
}

I'm getting this error:

message = "faultCode:AMFPHP_RUNTIME_ERROR faultString:'An active access token must be used to query information about the current user.'

I'm not very familiar to Facebook's graph api, and kinda of confussed because sometimes i can post correclty by calling my function, and other times gives me above's error. Maybe I need to somehow pass the token to my posting call ?. And what's the purpose of the 'cookie' argument in my call to log me into facebook ?.

Also, the access token is unique ?, or a different one is generated every time someone logs into the app ?.

Thanks for your orientation and thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

停滞 2024-10-05 00:36:57

如果您没有请求对您为尝试进行身份验证的用户创建的应用程序进行离线访问,则您需要先登录 Facebook,然后该应用程序才能运行。它与 AMFPHP 没有任何关系。

我不知道你正在运行什么样的环境,但看看 本教程。您应该能够收集运行应用程序所需的信息。

    if (isset($_POST['tt'])){
        try {
            $statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> $_POST['tt'], 'cb' => ''));
        } catch (FacebookApiException $e) {
            d($e);
        }

请注意,$_POST['tt'] 是示例代码中表单设置的变量。例如,您可以在其中使用您想要的任何内容。

$statusupdate = $facebook->api('/me/feed', 'post', array('message'=>$myMessage, 'cb'=>'');

请密切注意步骤 3。在该代码示例中,他们提供了一些 FBML 标记,这些标记将负责将登录/注销按钮放置到您的页面上,以处理用户登录。这样您就不必在浏览器中维护另一个已登录 facebook 的选项卡。祝你好运!

If you have not requested offline access for the application you created for the user you are trying to authenticate with, then you need to login to facebook before the application will work. It doesn't have anything to do with AMFPHP.

I don't know what kind of environment you are running but take a look at this tutorial. You should be able to glean what you need in order to get your application running.

    if (isset($_POST['tt'])){
        try {
            $statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> $_POST['tt'], 'cb' => ''));
        } catch (FacebookApiException $e) {
            d($e);
        }

Note that $_POST['tt'] is a variable set by the form in the example code. You can use whatever you want in that for example.

$statusupdate = $facebook->api('/me/feed', 'post', array('message'=>$myMessage, 'cb'=>'');

Pay close attention to step 3. In that code sample they give some FBML tags that will take care of putting a login/logout button onto your page that will handle logging in the user. Then you don't have to maintain another tab in the browser with facebook logged in on it. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文