I’ve tried this to get an html element from a public facebook event page in a file i named proxy.php:
<?php
header('Content-Type: text/html');
$ch = curl_init('http://www.facebook.com/pages/Revive/137584936302228?sk=events');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch);
?>
And using this ajax to get the content from it:
$.ajax({
url: '/wp-content/themes/revive/proxy.php',
type: 'GET',
dataType: 'html',
success: function(data, textStatus, xhr) {
events = $('div#pagelet_events', data).html();
// events = $('#text-5', data).html();
$('#events-section').append(events);
},
});
But that isn’t working out for some reason. How I can I get this to work?
Thanks!
Update: So that got me closer but looking at the code that the proxy.php it’s not just a div#pagelet_events that’s loading on the page. Not sure if that makes sense. The only thing I can find referencing pagelet_events is this:
<script>big_pipe.onPageletArrive({"phase":3,"id":"pagelet_events","is_last":true,"css":["AJXaB","3cT\/s"],"resource_map":{"AJXaB":{"type":"css","src":"http:\/\/f.static.ak.fbcdn.net\/rsrc.php\/v1\/yO\/r\/qjFDIQwXiny.css"}},"content":{"pagelet_events":"\u003cdiv class=\"UIImageBlock clearfix fbxNullState\">\u003cimg class=\"UIImageBlock_Image UIImageBlock_SMALL_Image img\" src=\"http:\/\/c.static.ak.fbcdn.net\/rsrc.php\/v1\/y9\/r\/56JC9tUWl0q.png\" alt=\"\" width=\"32\" height=\"32\" \/>\u003cdiv class=\"UIImageBlock_Content UIImageBlock_SMALL_Content\">\u003cp>You have no upcoming events.\u003c\/p>\u003c\/div>\u003c\/div>"},"tti_phase":3});</script>
Any idea if I can pull the content that this script is generating?
Thanks again!
I think Facebook blocks any request if it comes from (or looks like its coming from) a script/bot. You need to add in a user-agent string to make it seem like it’s a real request.
I modified your proxy script to this and it works (returns a result).