通过Facebook的图形api发布状态 [英] Posting status via Facebook's graph api

查看:180
本文介绍了通过Facebook的图形api发布状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,我试图使用图形api发布一个状态到我们的Facebook粉丝页面,尽管下面的内容facebook给出,以下代码似乎没有更新状态。

In PHP, I am trying to post a status to our Facebook fan page using the graph api, despite following the intructions facebook give, the following code does not seem to update the status.

以下是代码:

$xPost['access_token'] = "{key}";
$xPost['message'] = "Posting a message test.";

$ch = curl_init('https://graph.facebook.com/{page_id}/feed'); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xPost); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); 
curl_setopt($ch, CURLOPT_CAINFO, NULL); 
curl_setopt($ch, CURLOPT_CAPATH, NULL); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 

$result = curl_exec($ch); 

有人知道为什么这个代码不工作吗? access_token是正确的。

Does anyone know why this code is not working? The access_token is correct.

推荐答案

    $url = "https://graph.facebook.com/ID_HERE/feed";
    $ch = curl_init();
    $attachment =  array(   'access_token'  => 'your token',                        
                        'name'          => "Title",
                        'link'          => "www.google.com",
                        'description'   => 'description here',
                    );

    curl_setopt($ch, CURLOPT_URL,$url);
    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);
    $result= curl_exec($ch);

    curl_close ($ch);

这篇关于通过Facebook的图形api发布状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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