简体   繁体   English

facebook使用oauth登录

[英]facebook login using oauth

<?php
require "facebook.php";

$facebook = new Facebook(array(
    'appId'  => '3288@@@@@@@@@@',
    'secret' => 'ca2@@@@@@@@@@@@@@@@@@',
));

$user = $facebook->getUser();

if ($user) {
  try {
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    $user = null;
  }
}
?>
<?php if ($user): ?>
    <form action="#" method="get">
      NAME:  <input type="text" name="name"
            value="<?php echo $user_profile['name'] ?>"><br>
        KID'S NAME <input type="text" name="kid"><br>
        DOB <input type="text" name="kid" value="<?php echo $user_profile['birthday'] ?>"><br>
        ADDRESS <input type="text" name="kid" value="<?php echo $user_profile['email'] ?>"><br>

        KID'S GENDER 
        male<input type="radio" name="r" value="male">      
        female <input type="radio" name="r" value="male"> <br>      
    EMAIL:   <input type="text" name="name"
            value="<?php echo $user_profile['email'] ?>"><br>
        <input type="submit" value="Continue &rarr;">
    </form>
    <a href="<?php echo $facebook->getLogoutUrl() ?>">
        Logout of Facebook
    </a>
<?php else: ?>
    <a href="<?php echo $facebook->getLoginUrl() ?>">
        Login with Facebook
    </a>
<?php endif ?>

I have created the app and I have the app id and secret key . 我创建了应用程序,我有应用程序ID和密钥。 Now I need whenever the new user click on the login page , it will pre filled the form pages but when I am logged in , its just showing my details and when another user logged in , its showing me nothing 现在我需要每当新用户点击登录页面时,它会预先填写表单页面,但是当我登录时,它只是显示我的详细信息,当另一个用户登录时,它显示我什么都没有

It's showing your information because you created the app and you automatically are given permission. 它显示了您的信息,因为您创建了应用程序并自动获得了权限。

For others, you need your app to ask for their permission first. 对于其他人,您需要首先请求他们的应用程序。

The first thing you should do is this: 你应该做的第一件事是:

$params = array(
  'scope' => 'read_stream,publish_stream',
  'redirect_uri' => 'https://www.myapp.com/login_approved.php'
);
$url = $facebook->getLoginUrl($params);
echo '<a href="' . $url . '">Give My App Access!</a>';

And then create login_approved.php or whatever page you want to handle what happens when someone approves your app. 然后创建login_approved.php或任何您想要处理某人批准您的应用时会发生什么的页面。 Most notably it should record the user's access token. 最值得注意的是它应该记录用户的访问令牌。 You will need to provide the user's access token with your app's access token to get at their information. 您需要使用应用程序的访问令牌提供用户的访问令牌以获取其信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM