我用
PHP创建了一个简单的Facebook应用程序,通过用户名来迎接用户,
我也希望有电子邮件ID,以便显示.但我无法做到这一点.我正在使用的代码是,
我也希望有电子邮件ID,以便显示.但我无法做到这一点.我正在使用的代码是,
require_once('facebook.PHP'); require_once('config.PHP'); $facebook = new Facebook(APIKEY,SECRETKEY); $user=$facebook->require_login(); echo $user; // displaying the ID <div style="padding: 10px;" id="greeting"> <fb:if-is-app-user uid="loggedinuser"> <h2>Hi <fb:name firstnameonly="true" uid="loggedinuser" useyou="false"/>! welcome to facebook</h2> <fb:else> <h2>Hi <fb:name firstnameonly="true" uid="loggedinuser" useyou="false"/>! welcome to facebook</h2> </fb:else> </fb:if-user-has-added-app> </div>
我得到的输出是,
1000002020202020 Hi User! welcome to facebook
我希望电子邮件地址与用户名一起显示,我搜索了许多代码,但没有得到任何解决方案.如果你有任何好的Facebook教程网站,请发布链接..
您可以直接获取电子邮件地址,而无需使用FQL.
原文链接:https://www.f2er.com/php/134765.html// initialize facebook $facebook = new Facebook(array( 'appId' => APP_ID,'secret' => APP_SECRET)); $session = $facebook->getSession(); if ($session) { try { $fbme = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); } } else { echo "You are NOT Logged in"; } //getting the login page if not signned in if (!$fbme) { $loginUrl = $facebook->getLoginUrl(array('canvas' => 1,'fbconnect' => 0,'req_perms' => 'email,user_birthday,publish_stream','next' => CANVAS_PAGE,'cancel_url' => CANVAS_PAGE )); echo '<fb:redirect url="' . $loginUrl . '" />'; } else { // $fbme is valid i.e. user can access our app echo "You can use this App"; } // getting the profile data $user_id = $fbme[id]; $name=$fbme['name']; $first_name=$fbme['first_name']; $last_name=$fbme['last_name']; $facebook_url=$fbme['link']; $location=$fbme['location']['name']; $bio_info=$fbme['bio']; $work_array=$fbme['work']; $education_array=$fbme["education"]; $email=$fbme['email']; $date_of_birth=$fbme['birthday'];
这段代码对我有用……我会使用电子邮件ID获取所需的所有信息.
NOTE: User has to allow us to get their Information during the Approval of Application.