check publish_action permission using javascript - facebook

How can I check if the user has given permission and not disabled (publish_action) permission
to do post (publish_action) using open graph apis ?

Make a call to /me/permissions with the user's access token or /USER_ID/permissions with the app access token. It shows which permissions you have for that user.
Sample output is:
{
"data": [
{
"installed": 1,
"manage_pages": 1,
"user_actions.music": 1
}
]
}

Related

Facebook sdk /me/friends/ return empty data

I'm trying to get the names and ids of friends using my application, but the data is empty.
{
"data": [
],
"summary": {
"total_count": 1
}
}
I'm requesting the user_friends permission and it is included.
My all test Users include user_friends permission.
permmissions granted to my app
But I cannot get friends list.
Can someone help?

Getting empty friends list

My goal is to get a list of user facebook friends using Facebook Graph API. At least those, who have used social authentication on my website
I have read, that after v2.0 I can get only a list of friends, if the following conditions are met:
A user access token with user_friends permission is required to view
the current person's friends.
This will only return any friends who have used (via Facebook Login) the app making the request.
If a friend of the person declines the user_friends permission, that friend will not show up in the friend list for this person.
When I get a token and check
/v2.5/me/permissions
Result:
{
"data": [
{
"permission": "user_friends",
"status": "granted"
},
{
"permission": "public_profile",
"status": "granted"
}
]
}
I am testing 2 user accounts, who are friends. I have used both for login in my web application using Facebook Login.
But when I do
v2.5/me/friends
Result:
{
"data": [
],
"summary": {
"total_count": 1
}
}
What is the reason of empty friends set?
Make sure all those friends authorized your App with user_friends too. If they only authorized without user_friends, they will not show up. The response looks like it worked correctly.
Sidenote: It is not allowed to have 2 user accounts on Facebook, you can only have one account - with your real name.

Retrieving pages for a newly created admin user of a page returns empty

My applicaton uses this endpoint to retrieve a list of pages to which a user has access.
For my personal account, which is the admin of a page, it works fine:
https://graph.facebook.com/me/accounts?access_token=[accesstoken_for_my_personal_profile]
Results:
{
"data": [
{
"access_token": "<the access token>",
"category": "Record Label",
"name": "Page Name",
"id": "Page ID",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
]
}
]
}
But when we create a totally new facebook profile (regular user, as per my personal one) - and get it verified using mobile phone / SMS based verification, it only ever returns blank here, despite being given page admin access to the same page and having requested an access token exactly the same way:
https://graph.facebook.com/me/accounts?access_token=[accesstoken_for_newly_created_profile]
{
"data": [
]
}
UPDATE
The access token permissions are also different.
So when calling https://graph.facebook.com/me/permissions?access_token=xxx, the bad user only has public_profile and installed as 'granted' - but the good user has all the requested permissions including 'manage_pages'.
The URL used to request the tokens in the first place is here:
https://www.facebook.com/dialog/oauth?client_id=[my_app_id]&redirect_uri=https://www.facebook.com/connect/login_success.html&scope=manage_pages,read_mailbox,read_stream,publish_actions,user_likes&response_type=token
This directs to a login page which logs in as the user for which we want a token.
Courtesy of #CBroe above:
The issue here was that since API v2.0 came in, requesting access tokens for users who do not have a role in the requesting app will not assign certain permissions (in our case 'manage_pages') unless the app has been reviewed.

Add a Facebook App to a Page via API

I have a Facebook app and want to add it to a page programmatically without user interaction.
Exactly what this page does:
https://www.facebook.com/add.php?api_key=[my_app_id]&pages=1&page=[page_id]
But without the user having to confirm it. This is important as some users might need to do this for 100s of pages so confirming every single one is not really an option.
I searched around for this for a while and found some posts that suggest this should work:
https://graph.facebook.com/[page_id]/tabs?app_id=[app_id]&method=post&access_token=[access_token]
But I am always getting an
OAuthException: "(#10) Application does not have permission for this action"
When I check the permissions via https://graph.facebook.com/me/permissions?access_token=[...], I am getting this:
{
"data": [
{
"installed": 1,
"basic_info": 1,
"public_profile": 1,
"email": 1,
"read_insights": 1,
"manage_pages": 1,
"user_location": 1,
"user_friends": 1
}],
[ ... ]
}
Looks all right to me. I think manage_pages should be all I need?
Also, I can't find any official documentation about this and all posts about this are from 2011 or so. Has this function been removed maybe?
I am doing this on the server side (using PHP).
Eventually, I found the problem:
I need to use a page access token instead of a user access token.
It's mentioned in the API Reference here:
https://developers.facebook.com/docs/graph-api/reference/page/tabs/
Works fine now. manage_pages is the only permission I need.

Page access tokens from web app

I'm writing a facebook web app with Graph API for publishing on a page wall automatically. I'm the page administrator and I've set up the app permissions for requiring manage_pages, offline_access, read_stream and publish_stream. My app will be like twitterfeed app with something different (I've no rss feed as a source).
For the first step I call:
https://graph.facebook.com/oauth/access_token?client_id=".$app_id."&client_secret=".$app_secret."&grant_type=client_credentials
When this call return an access_token I call:
https://graph.facebook.com/100344706779072?fields=access_token&access_token=". $access_token
Here I have problems: as facebook doc says (https://developers.facebook.com/docs/reference/api/page/#page_access_tokens) I must get page_access_token in this way, but this call return only the page id..
So what I'm doing wrong?
From the facebook docs here: https://developers.facebook.com/docs/howtos/login/login-as-page/
you need to use the access token you got in the first call and make a second call to https://graph.facebook.com/me/accounts?access_token=$access_token
and you'll get a reply that looks like this:
{
"data": [
{
"name": "PAGE_TITLE",
"access_token": "PAGE_ACCESS_TOKEN",
"category": "PAGE_CATEGORY",
"id": "PAGE_ID"
},
{
"name": "PAGE_TITLE",
"access_token": "PAGE_ACCESS_TOKEN",
"category": "PAGE_CATEGORY",
"id": "PAGE_ID"
},
...
]
}