这种情况可能吗?
客户访问我的网站,想要下载一份他们感兴趣的PDF技术文档,他们点击下载按钮,然后会出现一个Facebook分享窗口,要求他们登录并将其分享到Facebook上。一旦他们点击分享并在其个人主页上发布,那么下载就开始了?
非常感谢。
Ian
这种情况可能吗?
客户访问我的网站,想要下载一份他们感兴趣的PDF技术文档,他们点击下载按钮,然后会出现一个Facebook分享窗口,要求他们登录并将其分享到Facebook上。一旦他们点击分享并在其个人主页上发布,那么下载就开始了?
非常感谢。
Ian
根据Facebook的新政策,此行为已不被允许。使用需自负风险,我不承担任何责任。
是的,使用JavaScript SDK,它提供了response
(现在不再提供)。
我们将创建一个if
语句来查看响应是否具有post_id
,如果是,则显示下载链接,否则执行其他操作(例如弹出警告框?)
HTML
<div class="container">
<div>
<p>This file is locked, to unlock and download it, share it</p>
<p class="hidden">Thanks for sharing, the file is unlocked and ready for download</p>
<p class="hidden">In order to download this file, you need to share it</p>
</div>
<a class="fsl fsl-facebook" href="#" id="facebook-share">
<span class="fa-facebook fa-icons fa-lg"></span>
<span class="sc-label">Share on Facebook</span>
</a>
<a class="fsl content-download" href="#" id="download-file">
<span class="fa-download fa-icons fa-lg"></span>
<span class="sc-label">Download File</span>
</a>
</div>
JavaScript(jQuery)
$('#ShareToDownload').on('click', function(e) {
e.preventDefault();
FB.ui({
display: 'popup',
method: 'share',
href: location.href,
},
/** our callback **/
function(response) {
if (response && response.post_id) {
/** the user shared the content on their Facebook, go ahead and continue to download **/
$('#ShareToDownload').fadeOut(function(){ $('#downloadSection').fadeIn() });
} else {
/** the cancelled the share process, do something, for example **/
alert('Please share this page to download this file'):
}
});
});
随着API版本2.0的发布,Feed对话框已被弃用,并被新的现代分享对话框所取代,因此上述代码使用了新的分享对话框
$.post('optimus.php', { 'fieldname' : 'download', 'value' : 'yes'});
<?php
session_start();
$_SESSION[$_POST['fieldname']] = $_POST['value'];
?>
Download.php 包含如下代码
<?php
session_start();
if($_SESSION['download'] == "yes"){
session_destroy();
$file = 'file.zip';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
} else {
echo "You didn't share, or you already downloaded the file";
}
?>