Javascript 在iframe中加载Facebook的替代方案

Javascript 在iframe中加载Facebook的替代方案,javascript,facebook,iframe,code-injection,Javascript,Facebook,Iframe,Code Injection,我被要求建立一个类似2010年Skittles社交媒体活动的网站,有些人可能还记得() 我的第一个想法是在iFrame中加载Facebook。当然不行(X-Frame-options)。 下一个想法:注入javascript来创建覆盖:不,在Facebook上不可能,但在YouTube上可以。 我能想到的最后一件事是重建Facebook的布局,并通过他们的API捕捉内容。这不是一个简单的解决办法 长话短说:有没有一种在Facebook上创建覆盖或将网站加载到我的网站背景中的平滑方法?您可以使用P

我被要求建立一个类似2010年Skittles社交媒体活动的网站,有些人可能还记得()

我的第一个想法是在iFrame中加载Facebook。当然不行(X-Frame-options)。 下一个想法:注入javascript来创建覆盖:不,在Facebook上不可能,但在YouTube上可以。 我能想到的最后一件事是重建Facebook的布局,并通过他们的API捕捉内容。这不是一个简单的解决办法

长话短说:有没有一种在Facebook上创建覆盖或将网站加载到我的网站背景中的平滑方法?

您可以使用PHP来获取页面,作为iframe的替代方案

$header = NULL;
$cookie = NULL;    
$ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, $header);
    curl_setopt($ch, CURLOPT_NOBODY, $header);
    curl_setopt($ch, CURLOPT_URL, "http://www.facebook.com");
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__). '/cookies.txt');
    curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookies.txt'); //save cookies here
    curl_setopt($ch, CURLOPT_REFERER, "http://www.facebook.com"); // you don't need that line; it's just the referer
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);;
    $output = curl_exec($ch);
curl_close($ch);
echo $output;
此外,使用cURL,您将能够在页面的输出处进行修改。

您可以使用PHP获得页面,作为iframe的替代方案

$header = NULL;
$cookie = NULL;    
$ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, $header);
    curl_setopt($ch, CURLOPT_NOBODY, $header);
    curl_setopt($ch, CURLOPT_URL, "http://www.facebook.com");
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__). '/cookies.txt');
    curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookies.txt'); //save cookies here
    curl_setopt($ch, CURLOPT_REFERER, "http://www.facebook.com"); // you don't need that line; it's just the referer
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);;
    $output = curl_exec($ch);
curl_close($ch);
echo $output;

此外,使用cURL,您将能够在页面输出时进行修改。

这实际上适用于Twitter,谢谢。Facebook和YouTube拒绝合作。顺便问一下,Facebook的输出是什么?我是否只需要回显$output?我不明白。我只是重新检查了代码。忘记提到您需要更改的URL并回显$output。我在上面编辑了我的答案。复制粘贴并再次测试代码。啊,谢谢。但一旦我与网站互动,我就会被转发到实际页面,对吗?有没有一种方法可以将页面完全保留在背景中,从而使覆盖层永久位于顶部?这实际上适用于Twitter,谢谢。Facebook和YouTube拒绝合作。顺便问一下,Facebook的输出是什么?我是否只需要回显$output?我不明白。我只是重新检查了代码。忘记提到您需要更改的URL并回显$output。我在上面编辑了我的答案。复制粘贴并再次测试代码。啊,谢谢。但一旦我与网站互动,我就会被转发到实际页面,对吗?有没有一种方法可以将页面完全保留在背景中,从而使覆盖层永久位于顶部?