从Codeigniter应用程序发布在Facebook的墙上 [英] Posting on Facebook wall from Codeigniter app

查看:84
本文介绍了从Codeigniter应用程序发布在Facebook的墙上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于CI的应用程序,允许用户发布类似Facebook的墙的更新流。



目前,用户可以通过Facebook使用FB连接。



我想提供一个用户的可能性 - 当张贴到我的应用程序的墙上 - 也可以发送相同的帖子到他/她的Facebook



看起来很清楚, FB的Graph API 支持这一点,但我很难找到一个路线图/代码/库来帮助这一点。上面链接上的例子是没有帮助的,不能给我如何实现这个。



例如,这个函数的控制器怎么样? / p>

我找到了Elliot的FB CI库这里,但不确定是否需要完成我想要的。



任何建议都非常感谢 - 感谢。

解决方案

我最后使用一个codeigniter helper函数与curl发布到Facebook。以下是代码。

  function facebook($ data){

$ CI =& get_instance();

$ CI-> load-> model('fk_model');

$ token = $ CI-> fk_model-> fk_cookie();

$ attachment = array(
'access_token'=> $ token ['access_token'],
'message'=> $ data ['text'],
'link'=> $ data ['link'],
);

$ ch = curl_init();
curl_setopt($ ch,CURLOPT_URL,'https://graph.facebook.com/'。$ token ['id']。'/ feed'); $ b $ c 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); //禁止curl输出
$ result = curl_exec($ ch);
curl_close($ ch);
}


I have a CI-based app that allows users to post an update stream similar to Facebook's wall.

Currently, users can authenticate into my app via Facebook using FB connect.

I would like to offer the possibility of a user -- when posting to my app's wall -- also be able to send the same post to his/her Facebook wall.

It seems clear the FB's Graph API support this but I'm having a hard time in finding a roadmap/ code/ library to help with this. The example on the above link is unhelpful and doesn't give me any idea how to implement this.

For example, how would a controller for this function look like?

I've found Elliot's FB CI library here, but am unsure if this is needed to accomplish what I want.

Any advice is greatly appreciated - thanks.

解决方案

I ended up using a codeigniter helper function with curl to post to Facebook. Below is the code.

  function facebook($data) {

    $CI =& get_instance();

    $CI->load->model('fk_model');

    $token = $CI->fk_model->fk_cookie();

    $attachment =  array(
        'access_token'  => $token['access_token'],
        'message'       => $data['text'],
        'link'          => $data['link'],
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/' . $token['id'] . '/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);  //to suppress the curl output
    $result = curl_exec($ch);
    curl_close($ch);
    }   

这篇关于从Codeigniter应用程序发布在Facebook的墙上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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