Using the Facebook Graph API and the PHP SDK, I know that I can get the user interests with
$facebook->api("/me/interests")
However, assuming that I have the permission to, how can I get the user's About data?
$facebook->api("/me/about")
//gives error:
Fatal error: Uncaught OAuthException: Unknown path components: /about thrown in
[...]/base_facebook.php on line 1028
How can I get the logged in user's Facebook About data? Thanks.
EDIT: Here's a picture of the app permissions, as well as the code used to request the permissions.
$login_url = $facebook->getLoginUrl(array( 'scope' => 'email, publish_stream,
user_about_me, user_interests, user_education_history'));
Depends what 'about' information you want? You can specify individual fields but there is no overall about command to get all about information. Just go
$info = $facebook->api('/me?fields=id,email,work');
You can get a full list of what you can request plus further commands from http://developers.facebook.com/docs/reference/api/user/
Edit, if you are wanting the bio just add ',bio' to the fields
That kind of errors Unknown path components: /xxx usually occur when you are not properly logged in your developer account.
It may sound obvious, But I had similar problems until habituate to check/change accounts before work. {>_<}
I think this should be :
$facebook->api("/me/bio") ;
EDIT:
Just Use this:
$facebook->api("/me") ;
You can get all user information from this . Just parse the array for what you required . It outputs all the user related information
Some attributes like users phone,address are specifically and intentionally not available via the API, for spam prevention reasons . Facebook does not allow them to take through api
Try with this :)
Related
I am trying to post to a Facebook account (with permissions) using the PHP
API. I am giving our users two options - posting to the Feed, and posting
to a specific facebook page. I am getting an error in the first case, but
not in the second case. In the code below:
$access_token is the access token I got back from linking to my app. It's of type
"User", and has the following permissions:
email
pages_show_list
business_management
pages_read_engagement
pages_manage_metadata
pages_read_user_content
pages_manage_ads
pages_manage_posts
pages_manage_engagement
public_profile
Where $page_token is, well, a "Page" type token, with the same set of permissions.
When I post to the page, it works fine. But when I try to post to the timeline, I get
the error:
Graph Error 200 : [Timeline]: [(#200) If posting to a group, requires app being
installed in the group, and either publish_to_groups permission with user token,
or both pages_read_engagement and pages_manage_posts permission with page token;
If posting to a page, requires both pages_read_engagement and pages_manage_posts
as an admin with sufficient administrative permission]
I'm not trying to post to a group, I'm posting to an account's timeline. And, per the
access token debugger, I have the permissions requested anyway. What's going on?
My code is below:
$linkData = [
'link' => $link_to_post,
'appsecret_proof' => $app_secret_proof
];
if ( POSTING TO TIMELINE )
{
$token = $access_token;
$post_to = "/me/feed";
}
else
{
$page_id = $page_id;
$token = $page_token;
$post_to = "/$page_id/feed";
}
// THIS THROWS THE EXCEPTION:
$response = $this->fb->post($post_to, $linkData, $token);
You can not post to a personal timeline via API any more, that was removed ages ago already. (With introduction of API v2.4, if I remember correctly.)
You can only use the Share or the Feed dialog, to offer the user a way to actively share / make a post themselves, https://developers.facebook.com/docs/sharing/web
I am trying to use Facebooks PHP SDK to login to my page. However, Facebook ignores the permissions given as an array in getLoginUrl()
$loginUrl = $helper->getLoginUrl(
['publish_actions']
);
The login url looks like:
https://www.facebook.com/v2.3/dialog/oauth?client_id=206265226055767&redirect_uri=http://host.tld/remote/gateway.php&state=67096befe627aa603cb086da681626c1&sdk=php-sdk-4.0.23&scope=publish_actions
However, Facebook still ask for my public_profile and my email
I have administrator privileges
The app is still in development mode
My Question is why Facebook ignores the scope parameter on the oauth login dialog.
Try with this code:
$params = array(
'scope' => 'publish_actions',
'redirect_uri' => 'https://www.myapp.com/post_login_page'
);
$loginUrl = $facebook->getLoginUrl($params);
Not sure if it works the same way with the PHP SDK 4.x though, but you can try this:
$scope = array('publish_actions');
$loginUrl = $helper->getLoginUrl($scope);
...from the well upvoted answer in this thread: Specify app scopes in php facebook sdk 4.0.0 or greater
Of course you can also write it like this:
$loginUrl = $helper->getLoginUrl(array('publish_actions'));
Not sure if it helps in your case, the literal array definition should definitely work in PHP...but you never know ;)
It's not being ignored
Initially Facebook shows a dialog so that the user can approve permissions to app, like profile, email, friends etc. What you're experiencing is specific to the publishing permissions like publish_actions.
Publishing permissions prompt a second dialog for the user to approve such permissions, which you'll get right after you take action about the permission request in the 1st dialog.
So,don't worry, it's not you, it's them.
Straight from the Facebook Permissions doc - https://developers.facebook.com/docs/facebook-login/permissions/v2.4#optimizing
Hoping that helped.
I have made new Facebook application, and when I am trying to allow "post to profile", I am getting this error:
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /home/mimota/public_html/gamingapp.com/test/src/base_facebook.php on line 1024
Thats part of the base_facebook.php file:
http://codeviewer.org/view/code:2263
I have marked there where is line 1024
I will really appriciate if some one could figure out whats wrong here, because I have no clue..
Thanks.
Use a URL of the following format to log into facebook:
https://graph.facebook.com/oauth/authorize?client_id=288229791195831&redirect_uri=http://www.facebook.com/connect/login_success.html&type=user_agent&display=popup&scope=publish_stream,user_photos,read_stream,email
They will give you a token back which you will use when you send requests:
For example to see get the main photo URL use:
https://graph.facebook.com/me/picture&access_token=THE_TOKEN_YOU_GOT_BACK
To post to wall replace /me/picture with whatever you need to post (sth like /me/wall)
it's weird this morning all my facebook applications don't work anymore. And when I use the graph API using request like : "graph.facebook.com/me"
I got :
{
"error": {
"type": "OAuthException",
"message": "An active access token must be used to query information about the current user."
}
}
Any idea?
Facebook did a developer update the past couple days..
http://developers.facebook.com/blog/post/518/
We had problems with the API key on older versions of the sdk, check that.
same thing here. I followed Ben Biddington's blog to get the access token. Same error when trying to use it. Facebook's OAuth implementation doesn't follow the spec completely, i am fine with it as long as the doc is clear, which obviously is not the case here. Aslo, it would be nice if the userid and username are returned with the access token.
You need to create an app so that you can get an appId and secret. Then you can create a facebook object like so:
$fb = new Facebook(array(
'appId' => $appId,
'secret' => $secret,
'cookie' => $cookie
));
and get the access token with $fb->getAccessToken(); this can then be appended to your graph api call url, and it should work.
when you click on facebook button, after login one cookie is generated with fbs_(token_access). by which it understands that you are logged in. may be because you are going directly you dont have sufficient access to get json encoded data..
this can be the problem for you.. make sure when you are loggedd in,cookie is generated ..
As the message states, you need to provide a valid access token. If you aren't providing one, then it obviously is the problem, as you need to have one, even when accessing your own information. If you are providing one, and it gives that error, then the token is not valid, which may be because it has expired or been revoked.
I have written an Application what posts Photos on a FanPage into a Specific Album long time ago.
Now I didn't used for a half year. Now I had to set up the Application again and grant the extended Permissions to the Fan Page (streamm_publish) again.
But now I've a Problem, I'm using the old REST API what now gives me the error: An unknown error ocurred with the error code 1.
Then I tried to post throught the Facebook Graph api.
I tried to make a call to the Api /pageid/albumid/photos what's not working(Unknown path components)
I tried to makea a call to /albumid_from_my_page/photos then the Photos were posted to my profile
I tried to upload it to /pageid/photos what is the same as the one above
But the code fpr the REST Api worked well, what's the problem there, and why the new Graph Api isn't working how she should?(BUG?)
To post a photo to an album, this is the code:
$post_data = array(
"message" => "My photo caption",
"source" => '#' . realpath($file)
);
$album_id = "XXXXX";
$facebook->api("/$album_id/photos", 'post', $post_data);
Now I suppose to interact with the page albums you need a page access_token added to your $post_data array, for this check this answer.
You need take ACCESS_TOKEN page...
try:
http://graph.facebook.com/me/accounts?access_token= GET THIS TOKEN USING GRAPH API... OR MAKE USING the getAccessToken()...
and will see all pages and aplications that u have, find just application for this case and COPY TOKEN... and damn!!!
It's possible to see this token thought GRAPH API EXPLORER...
regards.