Loading JSON background feed

I am trying to upload a facebook feed using jQuery on the client side of my site. The channel I use to request facebook is:

http://www.facebook.com/feeds/page.php?format=json&id=40796308305

I tried the following approbations:

1.

$.getJSON('http://www.facebook.com/feeds/page.php?format=json&id=40796308305',function(data){ console.log(data) }); 

Which returns an error:

XMLHttpRequest cannot load http://www.facebook.com/feeds/page.php?format=json&id=40796308305 . The origin of http: //xxxx.local is not allowed by Access-Control-Allow-Origin.

2.

 $.ajax({ url: 'http://www.facebook.com/feeds/page.php', type: 'GET', dataType: 'json', data: { id: '40796308305', format: 'json' }, success: function(data, textStatus, xhr) { console.log(data); } }); 

It returns the same error.

3.

 $.ajax({ url: 'http://www.facebook.com/feeds/page.php', type: 'GET', dataType: 'json', data: { id: '40796308305', format: 'jsonp' }, success: function(data, textStatus, xhr) { console.log(data); } }); 

Return:

Uncaught SyntaxError: Unexpected token:

And it seems the feed is parsing.

How to load facebook json feed so that I can access it, how do I make an array?

+3
source share
3 answers

You cannot do this on the client side only because of restrictions between domains.

You will probably need to create your own proxy server for this data (this endpoint for page data does not support JSONP and will not work with the callback parameter)

+1
source

Change data type from json to jsonp since its cross-domain call

0
source

I see that this branch is almost 6 months old, so I hope it’s not too late.

 function fbInfo(user, id) { var jurl = "https://graph.facebook.com/"+user+"&callback=?"; console.log(jurl); $.getJSON(jurl, function(data) { //do stuff }); } 

I call the function on my html page and pass the username ("user") of the facebook page to the url of the variable "jurl"

Use the $ .getJSON method, and then randomly manipulate the data.

This definitely works because I'm currently using it to pull business information from my facebook page to my website.

0
source

Source: https://habr.com/ru/post/958245/


All Articles