Facebook PHP SDK Issue with specific Facebook Id - facebook

Im using the following to retrieve information about Facebook pages that I'm the admin of. Specifically the number of likes.
// Get User ID
$page = $facebook->api($id);
return $page['likes'];
This works fine for 20 Facebook pages that I admin but I've run into one case where it does not. This is the error that I'm getting in response.
Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
I have checked that the Id being used is correct by viewing the Facebook Id Page under the admin settings. http://findmyfacebookid.com/ also runs into an error when entering the pages url.
Has anyone else experienced this? Is this a bug?

I am pretty sure you are not using an Access Token to grab the Page likes, and that one Page is restricted by age or country. Either that, or it is unpublished. Also, calling the return value "$user" may be misleading, it is not a User object, it is a Page object, right?
For restricted Pages you MUST use a User or Page Access Token of a User who can access the Page.

Related

Getting Facebook comments "From" field using Graph API [duplicate]

Recently, when using the /feed Facebook Graph API method, it has stopped returning the From field. This field typically contains the Id and Name of the author of the Facebook Post in question.
The URL I'm hitting is https://graph.facebook.com/{id}/feed?fields={my-fields-here}&access_token={token}
From what I can tell, the From field still exists within the API: If I try https://graph.facebook.com/{id}/feed?fields=id,from&access_token={token} I get a list of IDs (no Froms though), without errors.
However, if I try a deliberately-invalid field name, such as https://graph.facebook.com/{id}/feed?fields=id,doesnotexist&access_token={token} then I get an error response of (#100) Unknown fields: doesnotexist.
So the From field still exists as far as the Facebook Graph API is concerned. It's just no longer being returned. Did something change recently? The From field is also still listed as the list of fields over on their documentation. As far as the data itself goes, posts dating months back also no longer have From, so it's not a case of "newer posts in the feed lack the field, but older posts do either."
I'm at a loss! If anyone could lend a hand, I'd appreciate it.
It is only included if you use a Page Token. v2.11 of the Graph API (90-Day Breaking Changes):
/page/* — User information will not be included in GET responses for
any objects owned by (on) a Page unless the request is made with a
Page access token. This affects all nodes and edges that return data
for objects owned by a Page.
Source: https://developers.facebook.com/docs/graph-api/changelog/version2.11
...or in the link of your question:
Any valid access token can read posts on a public Page, but responses
will not include User information.
A Page access token can read all Posts posted to or posted by that Page, and responses will include User information.

How to get the featured video of a Facebook page

To fetch a Facebook page videos I use the code below:
new GraphRequest(mAccessToken, "Page_ID/videos", params, HttpMethod.GET, new GraphRequest.Callback(){}
What I want is to fetch the 'Featured video' of a Facebook page, but according to Facebook documentation in the link below, 'featured_video' parameter is visible only to the page admin, What is the logic behind setting this parameter to be only read by the page admin?
https://developers.facebook.com/docs/graph-api/reference/page/
Where can I report / ask Facebook to get this parameter result allowed to be read by others than the page admin?
Graph API /{page-id}/featured_videos_collection gives Featured Videos Collection for a Facebook Page. You need to use page-access token with page-id.
See for more info. I have not tested that API. Check if it is working.
You need to use {page-id}/featured_videos_collection edge to get featured video with normal user with page-access-token. While authenticating user, you need to get user_pages permission. Admin can get featured_video in directly without giving user_pages permission in {page-d} edge only. May be because of that Facebook have kept different edge for getting featured video of a page and 'featured_video' parameter is visible only to the page admin

Getting Stream from Facebook page with neosmart

Im using neosmart jquery plugin to get streams from facebook to my own page.
The plugin requires the page id from the fanpage, and mostly its working ok.
But with the link https://www.facebook.com/midtfynsgymnasium i cant get anything.
I guess the page id is 121130641250864 but i cant get the data. Is it because they have put on a "noread" attribute ?
The Facebook ID is only the last part of your address: https://neosmart-stream.de/facebook/how-to-find-a-facebook-id/
Additionally your access token needs the permission read_stream.

how to find graph URL for a page when http://graph.facebook.com/pagename doesn't work?

For most (all?) Facebook pages, I can access its graph data by getting the last part of its URL and adding it to http://graph.facebook.com. For example, http://graph.facebook.com/AKON pulls up data for http://www.facebook.com/AKON.
However, here's a page that doesn't work like that:
http://www.facebook.com/codblackops
Instead, http://graph.facebook.com/codblackops returns False.
What gives? And is there any way to figure out the correctly graph address from the www.facebook.com/codblackops page (or page source)?
If a page returns false then it is either because you're missing access_token privileges or due to geographical restrictions.
In order to make an access token that does not expire you can use the following question as a guideline: Do Facebook Oauth 2.0 Access Tokens Expire?
The biggest problem is even I have no access to that site. It's probably private/hidden, because it's redirecting me to the homepage. Check permissions and try again

Can't figure out how to get access token using facebook c# sdk

I'm currently writing a Facebook app that runs in a page tab. I'm writing it as a simple Web Forms app in C#, using the latest version of the C# SDK pulled from NuGet. The main page tab works fine. I get all the info I need from FacebookWebContext.Current.SignedRequest, and I'm fine there. I'm trying to write a page now that the page admin would use to set up the app, so this is the page that would go under the "Edit URL" in the app setup.
All I really want to do is get the currently signed-on user's ID, and determine if he's an admin for the page in question.
I'm doing this:
var client = new FacebookClient();
dynamic me = client.Get("me");
in Page_Load, and getting the following exception:
(OAuthException) An active access token must be used to query information about the current user.
I've tried a bunch of stuff to get the access token, but I don't seem to know what I'm doing wrong. Is there a straightforward way of doing this?
Update:
I figured out at one point that I had a reference to the old JS SDK on my master page, and that was causing a problem. (See here). Removing that got me to the point where I was usually able to see whether or not the user was actually logged in to Facebook.
Try this:
var fbContext = FacebookWebContext.Current;
if (fbContext.IsAuthenticated())
{
var client = new FacebookClient(fbContext.AccessToken);
dynamic me = client.Get("me");
}
As far as I understand, being logged-in in Facebook does not mean FacebookWebcontext.Current.isAuthenticated() == true. What Facebook wants to make sure is that the user has authorized the app. So what you should do is to forward the page to facebook authorization dialogue page (https://www.facebook.com/dialog/oauth?) with necessary permissions. Facebook will determine whether the app has been authorized by the user and redirect to the redirect_uri with a newer access_token issued.