Facebook Graph API v2.9 comment plugin count without access token - facebook

TLDR;
I want to be able to use the Javascript SDK to get the comment plugin count for a webpage. In the Graph API versions before 2.9 I could access this with the share endpoint without an access token, but since version 2.9 share is deprecated and replaced with engagement, which now requires an access token. I am aware that I shouldn't expose the app token to the client, so does anyone know how this can be achieved client-side using the Javascript SDK? The versions of the Graph API before 2.9 allowed me to do this using the share field, but this change will cause me to significantly change my code as it requires me to move my code from the client-side to the server-side. If possible I'd like to not have to do this. Does this change also not render the Javsacript SDK a little redundant, as all requests require an access token that shouldn't be accessible to the client?
Long version
For the Facebook Graph API v2.8 and lower I could get the count of the number of comments posted on a webpage that has implemented the Facebook comment plugin using the share field like this:
FB.api(
"/",
{
fields: "share{comment_count}",
id: url
},
function (response) {
if (!!response.error) return;
var commentCount = Number(response.share.comment_count);
}
);
The same thing is accessible by making this HTTP GET Request:
https://graph.facebook.com/v2.8/?id=URL_HERE&fields=share{comment_count}
Notice also, it doesn't require an access token which makes sense as this is publicly available info so no authorisation is necessary. This makes it simple to get the comment count using JavaScript on the client's browser using the Javascript SDK.
According to the change log from Graph API version 2.9 onwards:
GET /{url}/share - The share endpoint has been removed and replaced
with:
engagement field with subfields:
comment_count
comment_plugin_count
reaction_count
share_count
As a side note, if I look at the documentation for the engagement endpoint, it doesn't mention the subfields mentioned in the change log.
But my problem is that calling this HTTP GET request: https://graph.facebook.com/v2.9/?id=URL_HERE&fields=engagement{comment_plugin_count} requires me to have an access_token. If I use my app token it works. How can this be called on the client-side without exposing the app token? This was a simple task before using the share endpoint, but it seems unnecessarily difficult using the engagement endpoint considering the comment plugin count should always be publicly accessible without any authorisation.

Related

facebook api undocumented posts endpoint

I am working on an old codebase which includes a few fb api calls.
One of them is hitting /posts?ids=userId1,userId2...
When searching through the facebook api reference this endpoint is nowhere seen though.
https://developers.facebook.com/docs/graph-api/reference
You can try it in the fb api explorer though, for example with:
posts?ids= 89562268312
So my question, is this still a valid endpoint and does documentation exist?
Update:
according to Retrieving public posts from multiple Facebook pages at the same time using the Graph API this was once documented under the point selection, but it seems to be gone.
answering myself here in case someone stumbles over this, its not a direct endpoint, but as stated under
https://developers.facebook.com/docs/graph-api/advanced#largerequests
Multiple ID Read Requests
You can make a single GET request that retrieves multiple nodes by using the ?ids endpoint with the object IDs of those nodes. For example, to lookup the Facebook Developers page and the current session user in a single request, you could use the following Graph API call:
GET graph.facebook.com
/photos?ids={user-id-a},{user-id-b}

Can I access a Facebook Page with the Graph API without creating an app?

In the past, I think a Facebook Page access token could be generated manually, and then used with the graph API to query posts, comments, likes, shares, etc. Now it seems you cannot query anything without developing an app that I login to and then in turn the app generates the access token. Is that true? For example, this question from 2015 claims no access token is needed for public data, but when I try their example it returns "An access token is required to request this resource."
I'm the admin of my page that ran a basic contest (giveaway). I'd like to use the graph API to fetch the names of people that liked, shared, or commented on a post. Then I want to cross reference it with those that like the page. Do I have to register and develop an app for this? Does my page have an access token available without going through the app registration and review process?
Can I access a Facebook Page with the Graph API without creating an app?
No, that is not possible. You always have to use an App for any API Access.
Then I want to cross reference it with those that like the page.
That is not possible either, not even with an App. I assume you want to make sure that participants like your Page - which is not allowed. People cannot be "incentivized" to like your Page.
Platform Policy: https://developers.facebook.com/policy/
Explanation about the specific rule against requiring people to like your Page: https://developers.facebook.com/docs/apps/examples-platform-policy-4.5

How to use Facebook Embedded Post to show the latest post using Graph API?

I want to show a Embedded Post in my website, but I want it to be always the latest post on my fanpage.
What I'm trying to do is:
Query the posts by making a GET request to https://graph.facebook.com/{FANPAGE}/posts?access_token={TOKEN}
Get the ID of the first object
Add the plugin to DOM on runtime using the ID
The problem is that I can't figure it out how to get a permanent access token (or equivalent) - since I can't update it every time it expires and I don't want the user to login just to be able to see the plugin.
Can this be done? How?
You can use a page access token, or your app access token (the latter will work only if the page is not restricted and posts are not targeted to specific audiences.)
Both of those must never be exposed in public client-side code; so you will need to do this on the server.

Offline access to FB graph api from Javascript SDK

How do you query facebook's graph api via the javascript sdk for users that have allready given you permissions (offline access) and whose auth data you have stored, but who are not currently logged in to facebook?
To answer my question, you can in fact do so. You can use FB.api calls and include the access token at the end of the URL with ?access_token=
I'm not 100% sure of the code you'd need to actually do it, but I think one of the key elements to this would be logging in to the SDK as an application, rather than a Facebook User, as detailed in the documentation # http://developers.facebook.com/docs/authentication
Have you got an example query that you'd like to make with the SDK?

Using both Facebook Graph API and Old Rest API? Please help!

I am developing a Facebook application that will use Facebook events.
I want to be able to create and edit event as well as invite users friends to the event.
I prefer to use the new Graph API to handle all connections with Facebook and I many ways I am able too, but, the Graph API cannot send invites.
I saw that the Old Rest API got far more ways to interact with Facebook so I tried to use both systems on the same time but when I send the Access token that I have created with the Graph API a long with a call to the old API it says "Invalid OAuth 2.0 Access Token".
My question is, is there a way to convert the new Graph API access token to be used with the old rest API? Is there perhaps another way to get both systems to work in the same application?
Please help! All input are welcome.
I´d recommend against the old REST api. Support will be canceled sooner or later and then you will have to port to graph api anyway.
To send invites to your app you can use fbml/xfbml. try the http://developers.facebook.com/docs/reference/fbml/multi-friend-selector togehter with the JavaScript SDK as described here: http://www.takwing.idv.hk/tech/fb_dev/jssdk/learning_jssdk_11.html
good luck!