javascript - Facebook API 调用完成执行 Graph API 后调用 Javascript 函数[2.5]

标签 javascript jquery facebook facebook-graph-api facebook-javascript-sdk

我在网络应用中使用 Facebook Graph API 的发送消息功能。我想在用户单击 Facebook API 渲染的对话框的发送按钮后显示弹出的成功对话框,但目前它与 Facebook 渲染的对话框同时显示。

JavaScript 代码..

     function importfb(){
        reasonForAddFriend = "importFacebook";

        FB.login(function(response) {
            // handle the 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;
            });

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


        confirmationIndex("Success","importfb called");
    }

当前代码的输出..

send message fb api

我希望在点击上面屏幕截图中的发送按钮后不同时显示成功对话框..请帮忙..

最佳答案

始终查看 API 的相关文档。 FB.ui 采用第二个参数,即对话框关闭时将调用的函数。

https://developers.facebook.com/docs/javascript/reference/FB.ui#parameters

function(response)

This specifies the function that is called whenever the UI dialog is closed, either by success, cancellation, or errors. The response object will depend on the dialog being used. Consult the relevant dialog's own reference doc to see the response object that should be returned. Defaults to null.

因此只需传递一个回调函数并在那里调用您的对话框

FB.ui({
    method: 'send',
    link: 'http://www.google.com/',
},function(response){
    //check 'response' to see if call was successful
    confirmationIndex("Success","importfb called");
});

关于javascript - Facebook API 调用完成执行 Graph API 后调用 Javascript 函数[2.5],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35355373/

相关文章:

javascript - Google map API - 未捕获错误 : Module: 'earth' not found

jquery - 在JQuery中, "mouse events"是什么意思?

node.js - 如何在我的应用程序中使用Facebook登录

Javascript:在对象中分配变量时命名函数的好处?

javascript - 使用纯js将数据从node.js发送到前端

javascript - 创建iframe中的js对象

facebook - Symfony 2 Twitter 和 Facebook API

ios - FB 用户 emailID 未获取

javascript - if javascript 中 .datepicker 属性的条件

javascript - ajax 成功重新加载 div 内容不起作用