使用curl从网站发布到Facebook页面 [英] Posting to a facebook page from a website using curl

查看:114
本文介绍了使用curl从网站发布到Facebook页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个脚本,该脚本在提交按钮时将数据发布到Facebook页面。

I am trying to build a script which posts data to a facebook page when a button is submitted.

我创建了一个未过期的页面访问令牌,但是停留在如何建立网址上。图api资源管理器中的一些测试一直在给我:

I created a non expiring page access token but I'm stuck on how to build the url. Several tests in the graph api explorer keep giving me:

 {
      "error": {
        "message": "(#200) The user hasn't authorized the application to perform this action",
        "type": "OAuthException",
        "code": 200,
        "fbtrace_id": "BYNmxVAlESA"
      }
    }

我尝试了以下操作:

1745650152362669 / feed?message = message& access_token = myaccesstoken

1745650152362669/feed?message=message&access_token=myaccesstoken

1745650152362669 / feed?fields = message = message& access_token = myaccesstoken

1745650152362669/feed?fields=message=message&access_token=myaccesstoken

两者均作为 POST

虽然我确实为我的应用授予了权限。

While I did give permissions to my app.

就像您可以在这里看到的一样:

Like you can see here:

此令牌会在一个小时内过期,因此我按在打开访问令牌池

This token expires in an hour, so I press 'open in in access token pool'

然后点击扩展访问权限令牌:

And click extend access token:

我将该令牌再次粘贴到图形api资源管理器,但现在不再选择该页面:

I paste that token again in the graph api explorer but now the page is not selected anymore:

这就是应该的方式

我有以下代码应在提交时执行帖子:

I have the following code which should execute the post on submit:

<form>
    <input type="submit" name="submit">
</form>
<?

if(isset($_POST['submit'])){
    $token = 'mypageaccestoken';

    $attachment =  array(
    'access_token' => $token,
    'message' => $contentcr[0]['introtext'],
    'name' => $contentcr[0]['title'],
    'link' => $contentcr[0]['alias'].'html',
    'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/1745650152362669/feed');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close ($ch);
}

上面的代码目前没有在我的页面上发布任何内容,可以有人解释了我所缺少的内容吗?

The above code doesn't post anything to my page at the moment, can someone explain what I am missing?

推荐答案


用户未授权应用程序执行此操作操作

The user hasn't authorized the application to perform this action

该错误表示您缺少适当的权限。您需要 publish_pages 来发布(作为页面),而不仅仅是 manage_pages

That error means that you are missing the appropriate permission. You need publish_pages to post (as Page), not just manage_pages.

这篇关于使用curl从网站发布到Facebook页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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