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.
Related
i am using below code to share fb feed
FB.ui({
method: 'feed',
link: 'https://developers.facebook.com/docs/',
caption: 'An example caption',
}, function(response){ console.log(response); });
response is always null i could not figure out why , i think when share done it must output some response
ref link : https://developers.facebook.com/docs/sharing/reference/feed-dialog/v2.5
Please guide if i am missing something
There is only a reliable callback if you authorized the user with the publish_actions permission. In that case, you will get the Post ID in the callback.
Else, there is no way to determine if a user shared something.
Keep in mind that you are not allowed to reward users in any way for sharing according to the platform policy: How to upload multiple images to one post in facebook via api
I'm using the following Javascript for my users to send requests to "invitable friends" from my Facebook app:
FB.ui({
method: 'apprequests',
message: 'Come play with me etc.',
to: str_ids
},
requestCallback
);
function requestCallback(response){
if(response){
console.log(response);
}
else{
//show error to user
}
}
Where str_ids is a string containing the IDs returned by the invitable friends API. This all works fine.
When I invite a single user, let's say his Facebook ID is 1593894704165626, I get the following response:
request
"1399842883640198"
to
["1593894704165626"]
So here I have a unique request ID and the invited person's Facebook ID. I can now store this data in my database along with the inviter's ID, so I have all the necessary info.
However, now I want to reward the inviter after the invitee accepts the invitation and I'm running into a problem.
If user A and user B both invited user C, then when user C joins the game, how do I know whether to reward A or B?
I see from this question that it's possible to pass another parameter along with the invitation, which should help identify the inviter:
Facebook tracking who Invited whom
The first answer here suggests that you can pass such a custom parameter, but doesn't say how. Facebook's convoluted documentation is driving me insane.
Another thing - even if I send that additional parameter, I think there's a problem - for new users the app redirects to the Facebook page that checks whether they want to allow access to the app, and by the time they're redirected back to the app, the additional parameter will be lost.
Is there any solution to this?
The functionality that I need is to show a list of Facebook friends to the user on the website page with custom design, where the user can select some of them and send invites.
In API v2.0 it's possible to get a list of friends this way:
FB.api('/me/taggable_friends', function (response) {
...
});
But it doesn't return real users' ID that I need for invites with the next function call:
FB.ui({
method: 'apprequests',
message: invite_text,
to: 'user_id_1, user_id_2'
}, function (response) {
...
}
);
How can I get these real IDs?
Or how to resolve this functionality in another way? Because all the answers that I found were connected with games that don't fit me.
I need a full list of friends. Not just that already use my website (analog of the invitable_friends in-game section).
You are not allowed to use taggable_friends for inviting them, obviously it is for TAGGING friends and you only get a tagging token.
There is invitable_friends, but:
The invitable_friends API is only available for games that have a Facebook Canvas app implementation using version 2.0 of the Graph API.
(https://developers.facebook.com/docs/games/invitable-friends/v2.1)
I am afraid what you want to achieve is not possible. The proper way to invite friends to your website is to use the Send Dialog: https://developers.facebook.com/docs/sharing/reference/send-dialog
You can include one User ID in the "to" parameter. Of course it must be a User who authorized your App too, you can get those with /me/friends. Or better: Just open the Dialog and let the User select on his own.
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.
I suppose the answer is pretty simple, but i cant find conclusive answer either way.
Is it possible to use facebook to log in a user, fetch their friends, allow them to select them and then post to their profiles in turn, even if that means firing up a custom modal with html to select from the list of users friends before passing the IDs on to the publishStream function in a loop.
Any response would be dandy. Thanks guys and gals.
If you post to the logged-in user's stream, you have no control over which friends see it in their own streams.
Alternatively, you can send facebook notifications to friends that were selected, subject to the daily notification limit imposed on your app by facebook. Be aware that facebook is phasing out noficiations.
You can do exactly what you said. Just get the list of user IDs before hand using your custom dialog you mentioned. Then call the FB.ui function repeatedly, populating the "to" parameter with each friend ID.
FB.ui(
{
method: 'feed',
to: #,
name: 'name of post',
link: 'http://link.com',
picture: 'http://link.com/image.jpg',
description: 'descriptive text',
},
function(response) {
if (response && response.post_id) {
alert('Post was published.'+response);
} else {
alert('Post was not published.'+response);
}
}
);