Suggestions on a website that uses Facebook's Graph API - facebook

I'm trying to build a website with the following requirements. I need help to see if it's possible at all. This website has a regular login (not Facebook). Upon being logged in, the user has the option to "attach" his facebook account. At this point I save the return user id in the DB. Then, I tried on another computer the following Facebook Graph API call with this user id but it said:
Fatal error: Uncaught GraphMethodException: You can only access the "home" connection for the current user. thrown in /home/public/vendor/facebook/php-sdk/src/base_facebook.php on line 1294
The call:
/{user-id}/home
Appreciate help.

According to the error message you're trying to call /{user-id}/home but are using an access token from a different user -
You can't fetch another user's news feed, only the current user of your app, using their access token

Try {user-id}/feed. If you are not using the accessToken that was generated by the facebook API on the "attach" time, you will be able to get only the public feeds/data. Using the access token that was generated at the "attach" time, you will be able to get data for your app permissions.
About access token
https://developers.facebook.com/docs/facebook-login/access-tokens
How to use the graph api
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0

Related

facebook leads retrieval issue using graph api

Getting the following error while retrieving leads through graph api using form id. The same end point works fine for other users, but its not working for one of the users of the app. Not sure why its happening. Is there anything related to account type on facebook?
(#10) This endpoint requires the 'pages_read_engagement' permission or the 'Page Public Content Access' feature. Refer to https://developers.facebook.com/docs/apps/review/login-permissions#manage-pages and https://developers.facebook.com/docs/apps/review/feature#reference-PAGES_ACCESS for details.
https://graph.facebook.com/v9.0/<form_id>/leads?access_token=<>&appsecret_proof=<>
After adding pages_read_engagement in the scope list and making the user reauthorize the app the said api call is working fine but my query is why did it work for others.
The user does not have any role. User is following oAuth to permit the app to access his facebook pages and ad data

Error getting User data from Facebook

The login flow is working, I get a valid access token and everything. But when I retrieve the user data, I only get the name and userID. No email or other info from the public profile.
If I run a /me/permissions it returns granted on both email and public_profile. If I use facebook's Debug Tool with the access token it tells me the correct scope: email,public_profile.
So why am I not being able to get the data? I can't finish the signup process without it.
Any ideas?
As of Graph API 2.4, it no more returns several fields, you should explicitly ask for fields you want. See Graph API Changelog
Please read Graph API docs, especially this part about choosing fields

Facebook Application Token

I create a demo application to request photos from facebook. I created an application token like this : 549933848476397|4a584ce5fda19cba2ed6630ed78ba8f4. But when use this request URL https://graph.facebook.com/1417833425116725/photos?access_token={app_id}|{app_secret}. It's does not work. Please help me. Actually When I use user token for this request, It's work ok.
If the Page is restricted somehow (age, location), you can only use a User or Page Access Token to get data like photos of the Page. The App Access Token got no relation to any User, so Facebook canĀ“t detect if the User is even allowed to see the Page.
I am 100% sure the Page is restricted btw, you get an "Unsupported get request" error when trying to access the Page ID directly with the Graph API, and that usually happens when the Page is restricted.
Just try another Page with that exact same App Access Token, for example:
/bladauhu/photos
...works without any problem. Another sign that your Page is indeed restricted.
TL;DR: For this specific Page, you MUST use a User Token or Page Token.

retrieve Profile ID for Facebook Page Owner/Admin

In a previous version of the PHP SDK there was the ability in an App to get the Profile ID of the user that owned the page where the app was installed.
$facebook->get_profile_user()
This was possible without having the end user authorize access to the Facebook App.
However I can't find anything similar in the new JS or Graph API's. The closest thing I could find was the https://graph.facebook.com/<page_id>/admins, however it seems this call either doesn't work, or requires addition permissions:
Access Token:AAADF5PRI7BkBAKSz9Wqfbkuib6JH7WkZCQDZBgLNO10s1ZAMKF7BO7Y3YCVqkYNuCJ9QroWHYYn8n5wC8diPuBDPGsNUS5tDnZAZA6rFSx28VtpvVhUlY
Graph API: /210093142392039/admins
$this->facebook->api('/291231207559006/admins')
( ! ) Fatal error: Uncaught OAuthException: (#210) Subject must be a page. thrown in /html/classes/facebook/base_facebook.php on line 1033
Is this functionality gone? We were using the Profile ID as a key in a datasource, so it'd be ideal to keep this same key, if not we can start storing the page-id instead, however this would the users would have to reinitialize the app..
After September 22, 2011, manage_pages permission is required to do that.
You must request for the manage_pages permission, get the page access_token and then make the admins request with the page access_token.
Please refer to http://developers.facebook.com/docs/reference/api/permissions/ for updated permissions.
Well, I actually had the same problem some time back and found a solution for it. What i was doing was passing the user access token intead of the page access token. I would suggest that you should try something like
$pageIds=$facebook->api('/me/accounts');
$pageAccessToken=$pageIds["data"][1]["access_token"]; //get the access token for page "[1]" over here
and then try
facebook->api('/<page id>/admins', 'get' , array("access_token" => $pageAccessToken));

How to get the access_token for Facebook with no application

On the documentation page for Facebook Graph API there are a lot of example links such as https://graph.facebook.com/me/likes?access_token=SOME_AT
Could anyone explain how the access_token for these links are generated?
All I've read in the documentation were about getting access_token only for applications, but on that page everyone could get an access_token without one.
You can use the graph API to get public information. People set privacy settings on facebook, so to prevent social freaks from stalking you, they(fb) created Autorisation.What I believe is that on the documentation, they are generating the access token using the Developers App. You can generate this Access token by making an application and asking a user to Authorise your application to access his data using OAUTH dialogs. Usually people reading at developer.facebook.com have enabled the Developers app so it easily opens your information.
The Graph API as such allows you to
easily access all public information
about an object. For example,
https://graph.facebook.com/btaylor
(Bret Taylor) returns all the public
information about Bret. For example a
user's first name, last name and
profile picture are publicly
available.
To get additional information about a
user, you must first get their
permission. At a high level, you need
to get an access token for the
Facebook user. After you obtain the
access token for the user, you can
perform authorized requests on behalf
of that user by including the access
token in your Graph API requests:
The access_token in these links are generated using your Facebook identity and an application ID (presumable associated to "developers.facebook.com"). If you go to the same page with another Facebook account, you will see different access tokens.