在 Facebook API 调用完成执行 Graph API[2.5] 后调用 Javascript 函数
Call Javascript Function after Facebook API call has finished executing Graph API[2.5]
我在我的网络应用程序中使用 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");
}
当前代码的输出..
我想在点击上面截图中的发送按钮后显示成功对话框..请帮助..
始终查看 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");
});
我在我的网络应用程序中使用 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");
}
当前代码的输出..
我想在点击上面截图中的发送按钮后显示成功对话框..请帮助..
始终查看 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");
});