简体   繁体   English

如何在使用 facebook 时获取用户访问令牌与 PHP SDK3.0 连接

[英]how to get user access token while using facebook connect with PHP SDK3.0

Hye, i hav a situation.嘿嘿,我有情况。 im using php sdk3.0 for facebook connect and wanna signin users using there facebook id on my site.我使用 php sdk3.0 连接 facebook 并希望在我的网站上使用 facebook id 登录用户。 im saving current user's detail to my db, how can i get users access token to user it later on.我将当前用户的详细信息保存到我的数据库中,我怎样才能让用户访问令牌稍后再使用它。

Try something like this尝试这样的事情

<?php 
if ($_REQUEST['code']) {
    $app_id = "<app id>";
    $app_secret = "<secret key for your app>";
    $my_url = "<url to your app>";

    $code = $_REQUEST["code"];

    $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
        . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
        . $app_secret . "&code=" . $code;

    $access_token = file_get_contents($token_url);

    $graph_url = "https://graph.facebook.com/me?" . $access_token;

    $user = json_decode(file_get_contents($graph_url));

        echo $access_token . "<br />";
        echo $user->name . "<br />";
        echo $user->id . "<br />";
}
?>

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

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