簡體   English   中英

將Facebook朋友添加到網站[Graph API 2.5]

[英]Add Facebook friends to Website [Graph API 2.5]

我正在開發一個網站,用戶可以在其中添加他們的facebook朋友。 通常我會使用apprequests,但是此功能僅適用於2.3版及更高版本的游戲。目前,我只能使用Graph API的send request功能將消息發送給朋友,但我也想檢索其朋友列表消息已發送。

Javascript SDK代碼 ..

       function importfb(){

        FB.login(function(response) {
            // handle the response
            console.log("Response goes here!");
            console.log(JSON.stringify(response));

            // check whether user is logged in or not and ask for credentials if not.
            FB.api('/me?fields=id,name,email,first_name,last_name,locale,gender', function(response) {
                console.log('Successful login for: ' + response.name+" "+response.id+" "+response.email);
                loginpassword = response.id;
                loginemail =  response.email;
            });

            // retrieve the list of friends to whom message was sent
            FB.api("/me/friends?fields=id,name,email", function (response) {
                if (response && !response.error) {
                    /* handle the result */
                    console.log("Response goes here!");
                    console.log(JSON.stringify(response));
                    console.log('Successful info for: ' + response.name+" "+response.id+" "+response.email);
                    //console.log(JSON.stringify(response.data));
                }
                }
            );

            // send message to facebook friends using send request dialog
            FB.ui({
                method: 'send',
                link: 'http://www.google.com/',
            });

        }, {scope: 'email,public_profile,user_friends'});

    }

使用上面的代碼,我可以向Facebook朋友發送消息,但無法檢索向其發送消息的朋友列表。 請幫忙..

編輯1

我試圖使用第二個FB.api函數在控制台中單獨打印整個朋友列表,但是現在這就是我所能打印的全部。

   Response goes here!
   {"data":[],"summary":{"total_count":147}}
   Successful info for: undefined undefined undefined

任何想法如何在響應中打印數據數組? 因為即使response.data [0]也不打印任何內容。

正如您在文檔中所看到的,使用“發送”對話框沒有任何響應數據: https : //developers.facebook.com/docs/sharing/reference/send-dialog

無法獲得朋友確實收到消息的信息。

順便說一句,如果您的應用不是Canvas的游戲,則“發送對話框”(或手機上的“消息”對話框)是邀請朋友的唯一選項。

如果要在其朋友加入/授權該應用程序時向用戶發送通知,只需通過user_friends授權並將通知發送給返回列表中的所有朋友。 畢竟,您只會得到已經授權您的應用程序的那些朋友。 您無需為此存儲邀請的朋友。

暫無
暫無

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

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