3

Facebookでアプリを作成しています。ユーザーがアプリに入ると認証が行われ、その後、ユーザーのアクセストークンとIDを取得します。同じユーザーの詳細が必要で、それをデータベースに保存する必要があります.. ..これを行う方法私が試したコードはISです

 <?php 

     $app_id = "xxxxxxxxxxx";

     $canvas_page = "xxxxxxxxxxxxx";

     $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page)."&scope=email,user_birthday";

     $signed_request = $_REQUEST["signed_request"];
     //print_r($signed_request);

     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
     //print_r($payload);

     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
     //print_r($data);

      if(!isset ($_GET['code'])) {
                        if (empty($data["user_id"])) {
                          echo("<script> top.location.href='" . $auth_url . "'</script>");
                   } else {
                        $accessToken = $data["oauth_token"];

                          echo ("<br/><br/>Welcome User: " . $data["user_id"]);
                   } 
      } else {
          echo("<script> top.location.href='" . $pageUrl . "'</script>");
      }

 ?>

今、私は文字列または配列形式でユーザー名とその他の詳細が欲しい...助けてください....

4

2 に答える 2

15

このグラフ API を使用する:

https://graph.facebook.com/me?access_token=XXXXXXXXXXXXXXX

fields クエリ パラメータを使用して、返されるフィールドを選択できます。

https://graph.facebook.com/me?fields=id,name

于 2012-12-06T06:33:25.443 に答える
0

You can use the Facebook PHP SDK which automatically deal with this situation and sets the access token, or you may manually specify the access token using

setAccessToken($access_token) method

and pass it your user's access token and make Graph API call using api() method to get data about user. If you want to do away with the SDK then you need to add access token as parameter to Graph API end points.

于 2012-12-06T10:06:35.700 に答える