Can't create facebook album via graph api - facebook

I can't create a Facebook album via graph api. Now, it always throws a error
(#10) Application does not have permission for this action
I don't know why. I'm sure I have the correct access token (it is a valid, it does not expire). I have the same error in php & javascript.
My example code in js:
FB.api('/me/albums', 'post', {
access_token: access_token, // it is a valid
name: 'test album 1',
message: 'test album 1'
}, function(res) {
console.log(res); // throw a error "(#10) Application does not have permission for this action"
});
Does Facebook have some bugs or I missed something?
Edit: I found the correct answer from https://developers.facebook.com/bugs/680991411993635/:
Even though you are using a Page Access Token, you need the
user_photos permission in order to create a Photo Album as the Page.

Facebook does have some bugs...don't we all?
You actually did miss something - you need the correct permissions.
In order to create an album, you'll need to request the publish_actions permission from your users. This permission allows your application to publish stories to the users feed including new albums.

Related

Problems with facebook api posting to company page using application id: (#200) The user hasn't authorized the application to perform this action

I am stuck with access rights in trying to post on facebook company page.
I have created an application and gotten appId and secret.
I have linked the application to the existing facebook page.
I have retrieved an accessToken for the appId.
But get the response: "(#200) The user hasn't authorized the application to perform this action."
Which user does the error statement refer to? the AppId user? The administrators of the page (me)? And where can I grant these missing rights?
I am trying to achieve that the post functionality is not facebook-user-dependent, but is company (or appID) dependent.
I am really confused about this...
Off course we could create a bogus user (kept in the company files) and post as this user - but that goes against the Facebook policy, and that is not the road we want to go down...
function FB_doPost(link, message, accessToken) {
console.info('doPost');
FB.api('/pageid/feed', 'post', {
access_token: accessToken,
message: message,
link: link
}, function (response) { if (!response || response.error) { console.info('error occured: ' + response.error.message) } else { console.info(' post id: ' + response.id) }; }
);}
In order to post to a Page "as Page", you need to do the following:
Authorize a Page Admin with publish_pages and manage_pages
Use the /me/accounts endpoint to get a Page Token for that Page
Use that Page Token with the /pageid/feed endpoint to post as Page
Make sure you know about the difference between Access Tokens, here are some links about that:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/

Facebook Graph API access token is different from what I am getting via Oauth

I made a facebook app.
The app is to get all the pictures my page is tagged in.
When I use the graph api explorer with graph api explorer as the application to get the access token, This access token returns me all the data required(In this case photos my page was tagged in using (me/accounts) then get the access token of my page and then me/photos/tagged)
But the same process when I repeat with selecting my application in the graph api explorer. It does not give all the data
Both have same permissions.
Am I doing something wrong ?
I think is a little bug fix of API graph:
FB.api(
'/id_cta',
'POST',
{**"access_token":access_token**,"web_url":url},
function(response) {
console.log(response);
}
);
Important: ask for scope manage_pages and pages_manage_cta.

Check if user can write on a friend's Wall

If there any way to check in PHP SDK if user can write on specific friend's Wall?
Example:
if ($facebook_can_write_to->'123456789') echo "You can write on this friend's Wall";
Using the FQL table (http://developers.facebook.com/docs/reference/fql/user/) you can check to see if the current user can post to a friends wall by loading up the friend's user information specifically the can_post field.
can_post bool Whether or not the viewer can post to the user's Wall.
According to the documentation you can post on a user friends wall if that user granted you the *publish_stream* permission:
publish_stream
Enables your app to post content, comments, and likes to a user's
stream and to the streams of the user's friends.
There are some cases in which you won't be able to do so, for example if some user blocked your application then I guess it will fail if you try, so you should just check the response you get back from facebook for the api request and see if it worked or not.
Edit
As far as I'm aware you can not ask the api (nor via fql) "can my application post to this users wall", you can only ask "have this user granted my application the publish_stream permission".
If I understand what you want, I might have kind of a solution for you though.
I say show the user the option to post on a friends wall.
When the user chooses this option try to post on the friends wall (and I assume you are using ajax for that call), if it fails return some kind of code, then in the client side check for that code, if it returns use the javascript sdk to open a dialog.
You have two choices for dialogs, you can use the Feed Dialog like this:
var obj = {
method: 'feed',
to: "FRIEND_ID",
name: 'A message',
caption: 'Just trying something',
description: 'This is how to post on a friends wall'
};
FB.ui(obj, function(response) { console.log(response); });
Or you can use the Send Dialog:
FB.ui({
method: 'send',
to: "FRIEND_ID",
name: 'A message',
link: 'LINK_URL',
});
With this one though you have to post a link, I'm not sure if that works for you. After you tried and failed for a user you can save that data and use it later.

Facebook tagging user on a photo in a Page Gallery via SDK and Graph is possible?

I'm trying to tag a user (having its userid), with a Graph request made to a picture just uploaded to a Page Gallery.
Permissions I use in the app are:
#"read_stream", #"offline_access", #"publish_stream", #"manage_pages",#"photo_upload",#"user_photos" and with a access_token to the session got from page_it?fields=access_token item (that works for picture upload in gallery).
And I use them to upload the photo to a Gallery on a Fan Page successfully.
When I try to tag the user with a graph request in the form:
POST to picture_id/tags with param: "to"->userid
I get only facebookErrDomain error 10000 as if permissions are not right.
From API Documentation seems that only user_photos and publish_stream are required and no mention to page-galleries photo is made.
I'm quite clueless about this issue.
It's possible. You need to collect the page's specific token by placing a call to /me/accounts. And then tag the photo using page's access token. Once you get that, you can tag the photo using it's Graph Object Id and user id whom you are tagging.
if (accessToken) {
var data = {
"access_token": accessToken,
to:userId,
x:x,
y:y
}
FB.api("/" + photoId+"/tags/"+userId , 'post', data, function(response) {
//here is the response
});
}
Hope it helps. The key is the access token that is specific to that page :)

Is it possible to get the status of extended permissions for a Facebook app with the Graph or REST API?

I want to check the status of the extended permissions for a user of my Facebook app. I don't want to request permissions, I just want to know what permissions they have already granted access to. Is this possible?
I'm happy to use the Graph or REST API to do this in PHP or JS.
In the JS SDK you can perform an FQL query to get any extended permission:
FB.Data.query('select publish_stream, email from permissions where uid={0}', uid)
.wait(function(rows) {
var permissions = [];
if (rows.publish_stream) permissions.push("publish to stream");
if (rows.email) permissions.push("send email");
alert("Can "+permissions.join(", ");
});