How to get URL likes on Facebook in 2021 - facebook

Is a JSON response from Facebook still available? for links like my-websites.com?
I tried these answers but they no longer work: Getting the Facebook like/share count for a given URL
I found https://developers.facebook.com/docs/graph-api/reference/v10.0/link but there are no JavaScript - JSON examples.

Thank you #CBroe.
The documentations is here: developers.facebook.com/docs/graph-api/reference/v10.0/url
The JavaScript and JSON:
var url = "https://graph.facebook.com/?fields=engagement&access_token=ACCESS-TOKEN&id=WEBSITE-URL";
$.getJSON(url, function(json) {
console.log(json);
});

Related

How can I retrive facebook comments commented on my website?

I am using facebook comments on my website but is there any way to get the comments of my website post.
You can retrieve facebook comments for your URL trough the Graph API. Simply make an HTTP GET request to:
In the following example replace <Your token> with your access token
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "https://graph.facebook.com/v2.6/?fields=og_object{comments}&id=https://stackoverflow.com/&access_token=<Your token>", false );
xmlHttp.send( null );
console.log(xmlHttp.responseText);

Why do some Facebook urls not return their Facebook page id through graph api?

For most Facebook urls, a call to the graph api with a query string parameter of ids set to the url, returns the Facebook page of that url correctly....
https://graph.facebook.com/?ids=http://www.facebook.com/AdvantageInsulationNY&appToken&access_token=XXXXXXX
returns
{
https://www.facebook.com/AdvantageInsulationNY: {
id: "XXXXXX",
about: "about"
......
}
}
However, some simply return the url as the value of the id element...
https://graph.facebook.com/?ids=http://www.facebook.com/winetreefarm&access_token=XXXXXXXX
returns
{
https://www.facebook.com/winetreefarm: {
id: "https://www.facebook.com/winetreefarm"
}
}
I can't find an explanation of why this page does not return its page id or how to obtain the id (knowing the url) through the graph api.
I can get the id utilizing FQL, but only when sending the url as http (not https) and I want to use the graph api.
There is another question similar to this here: Facebook Graph API - get ID for a URL?
But none of these answers fit my situation (there is a like button on the page).
Any ideas?
Thanks,
Matt
I figured it out. This has to do with page restrictions and the token you are using. Because the page is marked as alcohol content its not viewable to anyone, so just my app token isn't good enough. If I access it with the user token, then I get the full information.

API Error Code 1383146 in Facebook Canvas API for Unity while making payment

I have implemented payments in my Unity app and have defined products in HTML form in my server, and have crawled them with FB's debug tool. The products are identical to Facebook's payments example apart from pricing and naming, as well as the photo link.
Yet, when I run FB.Canvas.Buy after deploying the app to Canvas, I get the following error:
An error occurred. Please try again later.
API Error Code: 1383146
API Error Description: invalid og type. Expected og:product, got website
This error has no documentation I can seem to find on any search engine or on Facebook's own documentation.
Any help would be appreciated, thank you.
I found the problem was I was passing the actual URL of the HTML product into the pay dialog rather than the graph object ID.
When using the graph object ID, I am finally able to perform purchases.
I meet the same error code 1383146 and found the root cause.
In the beginning i expect the product URL will be my current URL plus product.html. For example. My page is https://a.b.c/def/ and i expect FB to parse my product page https://a.b.c/def/product.html
var productURL = window.location.href + 'product.html';
var obj = {
method: 'pay',
action: 'purchaseitem',
product: productURL
};
FB.ui(obj, function(data) {
...
});
But i found FB will add query string when POST to my canvas page URL in some cases. URL will become https://a.b.c/def/?fb_source=search&ref=ts&fref=ts. Then my code will be wrong because i use window.location.href. So i update code and never meet 1383146 issue.
var productURL = window.location.protocol + "//" + window.location.host + window.location.pathname + 'product.html';
var obj = {
method: 'pay',
action: 'purchaseitem',
product: productURL
};
FB.ui(obj, function(data) {
...
});
In my case, the Facebook scraper could not reach the web server that is hosting the products (it could only be reached from our office, which I did not know). In that case, Facebook constructs a default object of type website and then complains about that.
You can see this in action with the Facebook Sharing Debugger. Enter your product URL, and hit the 'Debug' and maybe 'Scrape Again' buttons. It will show 'Warnings That Should Be Fixed'. It will only show the first warning by default, make sure you show all warnings. For me, one of those warnings further down was 'Cannot Connect To Server'. So that was the REAL problem

Facebook wall post is appending link with `accessToken`

I am using Facebook's Javascript SDK to post to a users wall.
The code which performs the actual post is:
linkUrl is a fully qualified domain name.
FB.ui({
method: "feed",
link:linkUrl,
picture:imgUrl,
name:title,
"description":description,
actions: [
{name: linkUrl, link: linkUrl}
]
},
function (response) {
if (response != null || response != undefined) {
fadeOutAlert = true;
self.fbMessageLabel.innerHTML = "Thank you, your Facebook post has been successful!";
self.fbMessageDialog.dialog("open");
};
});
The post works perfectly well and appears on the users wall, however the link has Facebooks access_token appended to it. So rather than linking to my.website.com it's actually linking to my.website.com/#access_token=aReallyLongAccessToken&expires_in=5684
Is there a way to prevent the access_token from being appended to the link?
bah.. I have been playing with this for DAYS now.. and just figured it out.
Ok, so for others that may have the same problem..
You need to go to the settings on the app and select the Permissions options.
Then set Authenticated Referrals to disabled, as in the image below. This will stop Facebook adding the access_token to your links.

c# post photo on facebook without using c# sdk

please provide me a simple piece of code in c# to post photo on facebook without using the very famous facebook sdk for c#, as per my knowledge there are two methods of posting photos,
METHOD 1:
The fb documentation below shows a method to post image with the url provided,
https://developers.facebook.com/blog/post/526/?ref=nf
of course I tried, it does not seem to accept my image url, when I tried debugging here on facebook API explorer using the post method and entered the parameters as below,
SomeAlbumID/photos?=access_token=MyTOKEN&url=http%3a%2f%2fcutree.com%2fcutreefbapp%2fimg1.bmp&message=Family+Tree
It returns an exception saying
{
"error": {
"message": "http\u00253a\u00252f\u00252fcutree.com\u00252fcutreefbapp\u00252fimg1.bmp is an internal url, but this is an external request.",
"type": "CurlUrlInvalidException"
}
}
"internal url, but this is an external request." I am not sure what this means as I am using the same domain as registered on my fbapp, and also giving the request from the server itself.
I have read some where that fb accepts images from only a few servers, can anyone help me out.
METHOD 2:
This is a method where image data in bytes are atttached with the Post body as fb says "To publish a photo, issue a POST request with the photo file attachment as multipart/form-data."
However everyone does that using the fb sdk for c#, can anyone provide simple http post method for this issue.
I have tried streaming image data using a method below
public MyFacebookClass FBPost(string URI, string Parameters)
{
System.Net.WebRequest req = System.Net.WebRequest.Create("https://graph.facebook.com/" + URI);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = BmpToBytes_Serialization(new Bitmap("C:\\Users\\atul\\cutreefbapp\\DefaultThumb.bmp"));
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
System.Net.WebResponse resp = req.GetResponse();
if (resp == null) return null;
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
return new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<MyFacebookClass>(sr.ReadToEnd().Trim());
}
Posting photos by giving a parameter url definitively works. If it doesn’t for you, then you are doing something wrong.
(I just tried it with the URL of your picture on the Graph API Explorer, and it work as I expected it.)
when I tried debugging here on facebook API explorer using the post method and entered the parameters as below,
SomeAlbumID/photos?=access_token=MyTOKEN&url=http%3a%2f%2fcutree.com%2fcutreefbapp%2fimg1.bmp&message=Family+Tree
If that’s the actual address you tried to post to, then the = between photos? and access_token is clearly wrong.
The problem you have is your code isn't correct. In order to post a photo to Facebook you'll need to use a multi-part form data post. I haven't used the C# SDK, but I'm sure it builds a multi-part form post internally before submitting the image.
You will have to do something similar to what is posted here. I was about to post my code that does this exactly for Facebook from my app, but it is a bit long.