[英]is there proper codeigniter library to work with facebook php sdk
I have searched Google for Libraries for Facebook
, and have found this one: http://www.haughin.com/code/facebook/ , but it seems a bit outdated. 我已经在Google上搜索了Facebook
库,并找到了这个库: http : //www.haughin.com/code/facebook/ ,但是似乎有些过时了。 I wanted something for this one: https://github.com/facebook/php-sdk/ 我想要这个东西: https : //github.com/facebook/php-sdk/
I have written my own wrapper for it meanwhile, but it seems like I'm having some issues with $_REQUEST['...']
同时,我为此编写了自己的包装器,但是好像我在$_REQUEST['...']
遇到了一些问题
You can use Official PHP Facebook SDK in Codeigniter easily. 您可以在Codeigniter中轻松使用Official PHP Facebook SDK。 The only problem is Facebook SDK needs $_REGISTER and in Codeigniter you don't have it.(Because of the mod_rewrite) 唯一的问题是Facebook SDK需要$ _REGISTER,而在Codeigniter中则没有它。(由于mod_rewrite)
Here's the little solution: 这是解决方案:
1- This is for the $_REGISTER problem. 1-这是针对$ _REGISTER问题。 Use this before loading Facebook class: 在加载Facebook类之前使用此方法:
parse_str( $_SERVER['QUERY_STRING'], $_REQUEST );
2- Facebook SDK has 2 files. 2- Facebook SDK有2个文件。 Put them into one file and save it to your application/helper folder as facebook_helper.php . 将它们放在一个文件中,并将其作为facebook_helper.php保存到您的application / helper文件夹中。 Then loading and using is such an ease like this: 然后加载和使用是这样的轻松:
$this->load->helper( 'facebook' );
$facebook = new Facebook( array( 'appId' => 'XXX', 'secret' => 'xxx' ) );
// ... The rest is not different. You can read Facebook SDK examples
So here's a trick I used to use facebook PHP sdk with my CodeIgniter app. 因此,这是我过去在我的CodeIgniter应用程序中使用facebook PHP sdk的一个技巧。 From the SDK code, take Facebook.php and take out the FacebookApiException class, and put it in a new file called FacebookApiException.php. 从SDK代码中,获取Facebook.php并删除FacebookApiException类,然后将其放入名为FacebookApiException.php的新文件中。 Now, I put facebook.php and FacebookApiException.php into the models folder, and used them as regular models. 现在,我将facebook.php和FacebookApiException.php放入models文件夹,并将它们用作常规模型。
Here is the code I used for authenticating users and providing access to an application via Facebook. 这是我用于验证用户身份并通过Facebook提供对应用程序访问权限的代码。
function facebook_login(){
# Creating the facebook object
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXX',
'cookie' => true
));
# Let's see if we have an active session
$session = $facebook->getSession();
if(!empty($session)) {
# Active session, let's try getting the user info
try{
$uid = $facebook->getUser();
$param = array(
'method' => 'users.getinfo',
'uids' => $uid,
'fields' => 'uid, username, name, profile_url, pic_big',
'callback' => ''
);
$user = $facebook->api($param);
} catch (Exception $e){
$url = $facebook->getLoginUrl(array(
'req_perms' => 'user_about_me, email, status_update, publish_stream, user_photos',
'next' => site_url() . 'user/facebook_login',
'cancel' => site_url()
));
redirect($url);
}
if(!empty($user)){
# User info ok?
print_r($user);
// Add user oauth token and info to DB, and then redirect to some controller in your application.
redirect('/'); // redirect to homepage
} else {
# For testing purposes, if there was an error, let's kill the script
die("There was an error.");
}
} else {
# There's no active session, let's generate one
$url = $facebook->getLoginUrl(array(
'req_perms' => 'user_about_me,email,status_update,publish_stream,user_photos',
'next' => site_url() . 'user/facebook_login',
'cancel' => site_url()
));
redirect($url);
}
}
Hope this helps. 希望这可以帮助。
You can handle it in clear way by writing a small library by inheriting Facebook SDK class. 您可以通过继承Facebook SDK类编写一个小型库来以清晰的方式处理它。 Please follow my post on http://www.betterhelpworld.com/codeigniter/how-to-use-facebook-php-sdk-v-3-0-0-with-codeigniter to get it working. 请按照我在http://www.betterhelpworld.com/codeigniter/how-to-use-facebook-php-sdk-v-3-0-0-with-codeigniter上的文章进行操作。
还有Facebook-Ignited 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.