I am trying to get access of facebook pages through php SDK
Using php-sdk-4.0.13
Facebook app version v2.2
And redirecting url like this
https://www.facebook.com/v2.2/dialog/oauth?redirect_uri=http//www.example.com/john114614/settings&state=5255ad86fea19ab0e8d61776890d0224&scope=manage_pages&client_id=558252720931906&ret=login&sdk=php-sdk-4.0.13&ext=1431067051&hash=AeYVfkUZEGLy0wD_
Its stay at 302 status and redirecting to http//www.example.com/john114614/settings?code=blahbla.......
App id is perfect and more over this problem faced from last 5-6 days before that its working fine.
Please help me how i can resolve this issue?
Thanks
You didn't specify a response_type, see
https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.3#login
In your case, you get a code which your'd need to exchange to an Access Token afterwards. If you specify your login url as follows
https://www.facebook.com/v2.2/dialog/oauth?redirect_uri=http://www.example.com/john114614/settings&scope=manage_pages&client_id=558252720931906&response_type=token
it should work IMHO.
Solution for above problem
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
FacebookSession::setDefaultApplication('appid84', '0secret0a626c6');
$helper = new FacebookRedirectLoginHelper('http://tmd.local/fblogin.php');
try {
$session = $helper->getSessionFromRedirect();
}
catch(FacebookRequestException $ex) {
}
catch(\Exception $ex) {
}
if ($session) {
var_dump($session);
}
else
{
$loginUrl = $helper->getLoginUrl();
header("location:".$loginUrl);
exit;
}
Related
please help me, I am in little trouble. I am familiar with codeigniter.
but I struggling with Login in With Facebook button. I included all files like facebook.php and base_facebook. Its working in Localhost but not working on server. please help me to fix this issue. when I click login button it's responding blank. I given my controller coding below. Thanks in advance.
public function check_fb()
{
$this->load->model('users/users_model');
$appId = '************'; //Facebook App ID
$appSecret = '************'; // Facebook App Secret
$homeurl = 'Site URL'; //return to home
$fbPermissions = 'email'; //Required facebook permissions
parse_str($_SERVER['QUERY_STRING'],$_REQUEST);
$this->load->library('Facebook', array("appId"=>"******", "secret"=>"*******"));
$fbuser = $this->facebook->getUser();
// Here it self I did't get any response.
if(!$fbuser){
$fbuser = null;
$loginUrl = $this->facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
//echo $loginUrl; exit;
redirect($loginUrl);
}
else
{
$user_profile = $this->facebook->api('/me?fields=id,first_name,last_name,email,gender,locale,picture');
$user = new Users();
//echo "<pre>"; print_r($user_profile); exit;
if(!empty($user_profile)){
if(!empty($user_profile['id']))
{
$check=$this->users_model->check_login_facebook_id($user_profile['id']);
if($check)
{
echo 'already Exist';
}
else
{
$result = $this->users_model->update_login_facebook_id($user_profile['id']);
redirect($this->config->item('base_url').'users/dashboard');
}
}
}
}
}
Above code is working pretty cool..! I made mistake in library folder. I renamed base_facebook.php as Base_facebook.php, its case sensitive. if anyone face like this problem, just check twice your library files name. Facebook.php ,base_facebook.php, Fb_ca_chain_bundle security certificate.
im trying to just get PAGE/Event from facebook and im still in doubt about how to do it
and if im doing it right or am i totally of track?
// for permanet session
$session = new FacebookSession("permanet app token");
// If you're making app-level requests: (copy paste from facebook :P)
$session = FacebookSession::newAppSession();
// To validate the session:
try {
$session->validate();
} catch (FacebookRequestException $ex) {
// Session not valid, Graph API returned an exception with the reason.
echo $ex->getMessage();
} catch (\Exception $ex) {
// Graph API returned info, but it may mismatch the current app or have expired.
echo $ex->getMessage();
}
if ( isset( $session ) && $session->validate() ) {
if($session) {
try {
$user_profile = (new FacebookRequest(
$session, 'GET', '/PAGE/events'
))->execute()->getGraphObject(GraphUser::className());
print_r($user_profile);
} catch(FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
}
so im wondering is this wrong or is it okey i just wanna post events i don't wanna login and stuff like that
im sorry im not good at english or explaining, so if something is unclear please let me know and i will try to explain as best as i can!
If you just want to get public events from a page, when what you are doing is correct. Just make sure the events on the page are public.
You cannot, however, create or post events without logging in. Firstly, the API no longer allows you to create events via the API. Secondly, viewing private events will require to login so Facebook can determine if you have permission to view the event or not.
In a previous thread we were strugling with the Facebook login using a Laravel app. Now, as the user logs into our app using Facebook, we are trying to get his friend's list in order to provide some qualified suggestions. So, here's what we are trying:
Route::get('login/fb/callback', function() {
// A FacebookResponse is returned from an executed FacebookRequest
$helper = new FacebookRedirectLoginHelper('http://yoururl/login/fb/callback');
$session = $helper->getSessionFromRedirect();
$request = new FacebookRequest($session, 'GET', '/me/friends');
try {
$response = $request->execute();
$me = $response->getGraphObject();
} catch (FacebookRequestException $ex) {
echo $ex->getMessage();
} catch (\Exception $ex) {
echo $ex->getMessage();
}
print_r($me);//->getProperty("id"));
$user = new Giftee;
$user->name = $me->getProperty('first_name') . ' ' . $me->getProperty('last_name');
$user->email = $me->getProperty('email') . "#facebook.com.br";
$user->photo = 'https://graph.facebook.com/' . $me->getProperty('id') . '/picture?type=large';
$user->save();
});
As a result, we get:
object(Facebook\GraphObject)#146 (1) { ["backingData":protected]=> array(0) { } }
By reading the Facebook API docs, they pretty much say user_friends will only return friends of friends that already use your app and We could not see any login permission that would just return friends of friends (not only the ones using our app). In another words, is what we want really impossible?
You're not able to retrieve friends of friends. With Graph API v2.0, you even only get those friends of your app's users which also use your app.
And, all friends_* permissions have been removed. So I don't see a chance for you to implement what you want to achieve.
i still have a problem on http://www.whaelse.com/en/grau-gruen-schwarz/ with the share counter.
Twitter and Google+ works fine for me.
With this code i've tried to load the facebook shares.
function get_likes($url) {
$json_string = file_get_contents('https://graph.facebook.com/?id='.$url);
$json = json_decode($json_string, true);
return intval( $json[$url]['shares'] );
}
and then
function getSocialCount($url){
$urlCurrentPage = get_permalink($post->ID);
$strPageTitle = get_the_title($post->ID);
echo '<li>facebook<span class="facebooksticky">'.get_likes($url).'</span></li>';
}
echo getSocialCount( get_permalink($post->ID));
but i still get 0 shares counter.
Could be a caching problem, just try it again tomorrow. Or try this endpoint, used by sharedcount.com:
https://api.facebook.com/method/links.getStats?urls=%%URL%%&format=json
I am using the OpenId library from Zend with CodeIgniter and everything is working just fine except for the verify function.
$status = "";
if (isset($_POST['openid_action']) &&
$_POST['openid_action'] == "login" &&
!empty($_POST['openid_identifier'])) {
$consumer = new Zend_OpenId_Consumer();
if (!$consumer->login($_POST['openid_identifier'])) {
$status = "OpenID login failed.";
}
} else if (isset($_GET['openid_mode'])) {
if ($_GET['openid_mode'] == "id_res") {
$consumer = new Zend_OpenId_Consumer();
if ($consumer->verify($_GET, $id)) {
$status = "VALID " . htmlspecialchars($id);
} else {
$status = "INVALID " . htmlspecialchars($id);
}
} else if ($_GET['openid_mode'] == "cancel") {
$status = "CANCELLED";
}
}
The Openid library needs a Zend session to start so I also included that library. I am able to: enter openid, get redirected to 'openid-provider', validate there, and get redirected back.
However, I am not able to retrieve the 'openid_mode', so I'm not able to 'verify' the info. I don't understand what I'm doing wrong. Is it purely that this library will not work with CI without some heavy hacking?
Have you tried CodeIgniter’s OpenID library?
Zend's OpenId system is flawed in many ways (it doesn't work with Google, Yahoo etc). I think you'll be better off with this library instead: http://www.janrain.com/openid-enabled