2

私の問題は、ログインボタンを表示し、(ユーザーがログインすると)プロフィール画像、名前、および「ログアウト」リンクを表示することです。

FacebookのAPIドキュメント(ここではhttp://developers.facebook.com/docs/guides/web/#login)で、次の例を見つけました。

 <html>
  <head>
   <title>My Facebook Login Page</title>
  </head>
  <body>

    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId      : 'YOUR_APP_ID', // App ID
          channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          xfbml      : true  // parse XFBML
        });
        FB.api('/me', function(user) {
          if (user) {
            var image = document.getElementById('image');
            image.src = 'http://graph.facebook.com/' + user.id + '/picture';
            var name = document.getElementById('name');
            name.innerHTML = user.name
          }
        });
      };
      // Load the SDK Asynchronously
      (function(d){
         var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement('script'); js.id = id; js.async = true;
         js.src = "//connect.facebook.net/en_US/all.js";
         ref.parentNode.insertBefore(js, ref);
       }(document));
    </script>

    <div align="center">
      <img id="image"/>
      <div id="name"></div>
    </div>

  </body>
</html>

それは私が探していたものをするはずです。'MY_APP_ID'とMY_DOMAIN.COMをapp_idとドメインサイト(http://localhost/index.html)に置き換えました。また、ドキュメントで見つけたログインボタンを追加しました(これは機能し、ログインできます)が、画像も名前も表示されません。私はコンソールで「user」オブジェクトを作成しましたが、これは次のようになります。

error: Object
   code: 2500
   message: "An active access token must be used to query information about the current user."
   type: "OAuthException"

この「アクティブアクセストークン」はどのように使用すればよいですか?

4

1 に答える 1

3

ユーザーデータの取得を実行するには、すべてのFacebookアプリケーションが最初にユーザーセッションを認証して、アプリがデータを取得するエンドユーザーの権限を持っていることを確認する必要があります。

参照https ://developers.facebook.com/docs/authentication

Javascript SDKを使用してアクセストークンを取得すると、結果としてユーザーの表示名と画像の取得を開始できるようになります。

Facebook JS SDKhttps ://github.com/facebook/facebook-js-sdk/

于 2012-07-13T14:55:52.900 に答える