簡體   English   中英

按下贊按鈕后如何獲取用戶信息

[英]How to get user info after press like button

我有社交媒體工具欄。 而且我有facebook之類的按鈕,我的願望是當某人單擊facebook之類的按鈕而不是查找用戶並將相關信息存儲到我的數據庫中以進行促銷。

我做了這樣的

  window.fbAsyncInit = function() {

        FB.Event.subscribe('edge.create',
        function(response) {
            var FBGraphURL = "http://graph.facebook.com/user/callback=?";

            FB.getLoginStatus(function(res) { alert(res); });

            FB.api('/me', function(resp) {
                alert('Good to see you, ' + resp.username + '.');
            });
        });
    };

但是resp.username仍然顯示為undefined 我該如何解決這個問題?

更新

工作代碼:

window.fbAsyncInit = function() {
    FB.Event.subscribe('edge.create', function(response) {
        login();
    });
};

function login() {
    FB.login(function(response) {
        if (response.authResponse) {
            GetUser();
        } else {
            // cancelled
        }
    }, {scope: 'email'});
}

function GetUser() {
    FB.api('/me', function(resp) {
        alert('Good to see you, ' + resp.email + '.');
    });
}

另外,每個域必須具有不同的應用程序ID( 重要

like插件僅向您返回有關生成內容的URL。 要獲取用戶信息,您必須使用fb connect,並且當用戶接受您的應用程序時,您可以使用其訪問令牌檢索其信息!

在這里查看更多詳細信息: https : //developers.facebook.com/docs/howtos/login/getting-started/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM