I'm on my own page, I'm admin and I'm already "like" this peage, but this code:
require_once "api/facebook.php";
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => SECRET,
'cookie' => true
));
$signedrequest = $facebook->getSignedRequest();
$uid = $facebook->getUser();
gives me just this data:
### USER ID ###
0
### SIGNED REQUEST ###
Array
(
[algorithm] => HMAC-SHA256
[issued_at] => 1330166798
[page] => Array
(
[id] => 304887859549216
[liked] => 1
[admin] => 1
)
[user] => Array
(
[country] => us
[locale] => en_US
[age] => Array
(
[min] => 21
)
)
)
So, getUser() = 0 and user id from signed request - empty.
What im doing wrong?
By default the "user" is the page, this way you can display content from your app relevant to the page. To determine who the user is, you can go through the standard backend redirects you would go through as if the user came to your app with no session/expired token. But you need to remember what page your were on since Facebook only passes that information on initial iframe load.
For a better user experience, I would use the Facebook javascript SDK. You can check everything in javascript and determine who the user is without performing any redirects. You can even prompt for authorization without reloading the page. If the user already had authorized your app, they see no changes and get no prompts, but you now have a "session" with that user and know their ID in javascript.
https://developers.facebook.com/docs/reference/javascript/FB.login/
For getUser you need to log in in your application , show te login/permission dialog
Just to add to this you can't currently get everything in the javascript SDK. It doesn't give you any of the user or page (for page tab) data which PHP SDK does.
Related
My application is based on PHP Codeigniter and for LMS I am using a Moodle cloud instance. I want to make my application that supports LTI 1.3. For that, I am using this PHP library (https://github.com/1EdTech/lti-1-3-php-library) which helps me to handle LTI 1.3 login and launch. I successfully implement that library but I noticed after login when I create a session where I store user details ->
application/controllers/Login.php
$user_details['userID'] = 123;
$user_details['key'] = 'xyz';
$user_details['userName'] = "Anubhab";
$this->session->set_userdata('logged_in', $user_details);
later I will try to send that session to another controller but in moodle, I lost the session data ->
application/controllers/Redirect.php
$logged_in = $this->session->userdata('logged_in');
print_r($logged_in);
I am getting a blank array when I launch my application from moodle.
If I print the session object I get this
print($this->session);
Output:
CI_Session Object ( [userdata] => Array ( [__ci_last_regenerate] => 167646604 ) [_driver:protected] => files [_config:protected] => Array ( [cookie_lifetime] => 7200 [cookie_name] => ci_session567fgf [cookie_path] => / [cookie_domain] => [cookie_secure] => [expiration] => 7200 [match_ip] => 1 [save_path] => /var/www/univ/system/cache/sessions [_sid_regexp] => [0-9a-f]{40} ) [_sid_regexp:protected] => [0-9a-f]{40} )
In standalone and Openedx(while I launch my application from OpenEdx) I can successfully send the session data to another controller but in moodle, the same code did not work. If anyone please tell me the reason that will be really helpful.
Thanks in advance!
I've downloaded the Google API PHP and I'm trying it out with a "log in with Google" script.every think i working fine. but i want password field as well,to save my database for further login as normal user for my web portal.
i have use following code:
$service = new Google_Service_Oauth2($client);
if ($client->getAccessToken())
{
//For logged in user, get details from google using access token
$user = $service->userinfo->get();
$user_id = $user['id'];}
//list all user details
echo '<pre>';
print_r($user);
echo '</pre>';
and output of the $user is:
Google_Service_Oauth2_Userinfoplus Object
(
[internal_gapi_mappings:protected] => Array
(
[familyName] => family_name
[givenName] => given_name
[verifiedEmail] => verified_email
)
[email] => example#gmail.com
[familyName] => man
[gender] => male
[givenName] => deadman
[hd] =>
[id] => 123456789012345
[link] => https://plus.google.com/101978174620808672845
[locale] => en-GB
[name] => dead man
[picture] => https://******************/photo.jpg
[verifiedEmail] => 1
[modelData:protected] => Array
(
[verified_email] => 1
[given_name] => dead
[family_name] => man
)
[processed:protected] => Array
(
)
)
how to get password field from google?
The entire point of Google Sign-In is so you don't store a password for the user. The user is able to use their Google credentials to access your site - Google is authenticating them for you and telling you who the user is. (Remember that Google authentication may not even involve a password for you to store. If the user has setup two-factor authentication, there is no password involved.)
If you want to allow your users to log into your site without a Google account, or in addition to their Google account, then you might want to prompt them for a password for your site, but this is completely outside Google's authentication system.
If you think you need a password to access the user's information on Google - you don't. For most services, you should be using OAuth 2 which provides a safer way for you and your users to manage what you can do using Google's services.
You can not get password field of users in google auth or anyother social auth. This is for user security. There is a callback url option in console. User is redirected to that url if google login is authenticated.
I also try get data from getSignedRequest() (PHP-SDK 3.4) but page data is empty in response:
Array
(
[algorithm] => HMAC-SHA256
[code] => AQC94XuRCkLCYkJkBU2j2JvR_H0dEesyyWE9IOnBorRExZyjDhRR1M5JnG5CiWLf12xuO0CiFzVva05D-L3NNuId-IbOg4VO8X-DENRlbj3CiSIzBn....
[issued_at] => 1408109031
[user_id] => 6660247934796
)
The 'liked' property will no longer be returned in the 'signed_request' object for Page Tab apps created after today.
https://developers.facebook.com/docs/apps/changelog
See v2.1 updates, Fangates are not possible anymore, and not allowed according to the platform policy of Facebook.
My Two page facebook application contains
index.php
welcome.php
On index.php
$signed_request = $facebook->getSignedRequest();
works fine and i can get page id
but when i click on welcome page, and try to get page id,
$signed_request does not fetch page id.
[algorithm] => xxxx
[code] => xxxxx
[issued_at] => xxxxxx
[user_id] => xxxxxxx
got this but couldn't get page id
You only get $signed_requeston the first page. You should save it in a session if you want to use it on another page.
I m working on a facebook iframe application.
Facebook $_REQUEST response is as bellow:
Array
(
[signed_request] => some value
[PHPSESSID] => somevalue
[fbs_251034681599274] => somevalue
)
but i want one more parameter to its REQUEST so i want its response like bellow
Array
(
[fb] => some value
[signed_request] => some value
[PHPSESSID] => somevalue
[fbs_251034681599274] => somevalue
)
and that fb key will be dynamically.
Please help me how can i do it.
Best Regards,
Krishna Karki
If you want to identify users you need to use fb authorization (https://developers.facebook.com/docs/guides/web/#login) and then you can get some unique ids
OR you can generate that keys on your server (where that iframe source is)
if you just want to send some data with interaction on that iframe, do it same as you do it on a non-iframe-facebook-app page.