0
我想創建一個函數,在提交時在Facebook上分享內容,如果複選框被選中,就像Ask.fm上的回覆表單(我現在相信你在說什麼)。我想根據這裏的一些答案如何打開復選框點擊Facebook授權彈出窗口,但事情是,我想保持未經檢查,直到用戶授權並給所有必要的權限給Facebook應用程序。更確切地說,您點擊複選框,Facebook Login彈出窗口打開,但複選框保持未選中狀態,直到您授權具有所有必需權限的應用。到現在爲止我有這樣的代碼:如果選中複選框,在Facebook牆上發佈消息
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
window.fbAsyncInit = function() {
FB.init({
appId: 'APP_ID',
status: true,
cookie: true,
xfbml: true
});
};
(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));
$('#checkbox').change(function() {
if ($(this).is(':checked')) {
FB.login(function (response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function (response) {
console.log('Good to see you, ' + response.name + '.');
});
} else {
alert('User canceled login or did not fully authorize the app.');
}
}, {
scope: 'publish_stream,email',
return_scopes: true
});
}
});
function fb_publish() {
var msg = $('#message').val();
FB.ui({
method: 'stream.publish',
message: msg,
attachment: {
name: 'Name here',
caption: 'Caption here.',
description: (
'description here'
),
href: 'url here'
},
action_links: [
{ text: 'Code', href: 'action url here' }
],
user_prompt_message: 'Personal message here'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
});
</script>
<form onsubmit="fb_publish()">
<input type="checkbox" name="facebook" value="1" id="checkbox" />Facebook
<label for="Message">Message</label>
<input name="message" id="message" type="text" />
<input type="submit" value="post" />
</form>
我不斷收到這樣的信息:「用戶取消登錄或沒有完全授權的應用程序」 – Alexander
你完全替換了代碼並試過了嗎? –