Facebook Event API, users does not receive notifications - facebook

After i invite friend via app (JS api) they don't have any way to accept invitation (they don't have notifications, or notification disappear directly on hover). So they are being invited, but don't even know about that.
Here is how i invite friend to event:
FB.api('/EVENT_ID/invited?users=USER_ID', 'POST', function(response){console.log(response);});

Request should look like that:
FB.api(
'/707089732635823/invited',
'POST',
{
access_token: FB.getAccessToken(),
users: '100007028615075'
},
function(response) {
console.log(response);
}
)

Related

facebook api with private message multiple to (friends)

I development facebook private message for invite with facebook api.
<script>
FB.init({ appId: 'xxxxxxxxxx', xfbml: true, cookie: true });
FB.ui({
method: 'send',
to: ['1736383768','590528674'],
// picture: 'http://thinkdiff.net/iphone/lucky7_ios.jpg',
//Can be page, popup, iframe, or touch.
display: 'popup',
name: 'yyyyyy',
link: '<%=Request.QueryString["link"]%>'
});
</script>
but adds only the first mate.
how to multiple friends send private message ?
var publish =
{
method: 'stream.publish',
message: 'Some kind of test',
uid: uid,
attachment: {
name: 'Test',
caption: 'Facebook API Test',
description: ('Sure hope it worked!'),
href: 'http://www.test.com/',
media: [
{
type: 'image',
href: 'http://test.com/',
src: 'http://test.com/image.jpg'
}
]
},
action_links: [
{ text: 'Your text', href: 'http://www.test.com/' }
],
user_prompt_message: 'Share your thoughts about test'
};
publish.target_id = friendID;
FB.ui(publish);
publish.target_id = friendID;
FB.ui(publish);
return false;
You should not use stream.publish.
As said by facebook : "We are in the process of deprecating the REST API, so if you are building a new application you shouldn't use this function. Instead use the Graph API and POST a Post object to the feed connection of the User object"
So, now you have the send and feed methods left.
You cannot fill the send method with more than one user id (you can only if you are whitelisted by facebook, but I'm not quite sur how to do this , I would not count on it either).
You can use the feed method to post on many user's friends wall with something like this
FB.api('/USERID/feed', 'post', {
name:postName,
link:postLink,
picture:postPicture,
description:postDescription,
message:postMessage
}, function (postResponse) { //DO SOMETHING HERE });
But doing it, you are taking the risk of your app being deleted by facebook if someone flag it as spam.
As far as I know, sending messages to multiple friends via an App is considered bad/spam by facebook so they do not allow this anymore.
You still can Invite as many friends as you want via the App request dialog (method apprequests) but I'm not sure this is what you want.

Building an in-app request dialog

Is there a way of building a custom request dialog, and sending the selected userid(s), the app request. I don't want to be using the multi-friend selector form.
This function here should provide you the ability to send a request to a single person.
<script>
function sendFriendInvite(message,title,to,data){
FB.ui({method: 'apprequests',
to: to,
message: message,
title: title,
data: data
},
function(response) {
if (response && response.request_ids) {
//Sent!
} else {
//Not Sent
}
});
}
</script>
<a onclick="sendFriendInvite('Here is an invite','Send to Invite to Friend', 123456);">Send request to friend 123456</a>

Inviting selected users to Facebook-Event (via Graph API)

with help of docs, tutorials and this forum I managed to create an event for the logged in user on his profile or page, as he chooses.
I also figured, that for inviting friends I'd have to use events.invite.
Since I don't want to invite all of the user's friends but several, I implemented a request, which as a result returns the selected friend's ids.
Those I'm using for the events.invite call. I get bool 1 as result (which means, the invitation was sent successfully) but there is no invitation to be seen in friends bookmarks or event page.
Everything besides invitation is working.
3 questions come up:
1) Does events.invite need additional permission besides 'create_event' ?
I tryed events.invite independently and couldn't get results either...
2) Is there a better way to select friends before sending invitation? I do not want app request being sent out each time an event is created.
3) If 2 is negative, how can the app request (and bookmark) be subdued or removed from friend's profile? Deleting the request via API obviously doesn't remove the message in application requests.
* in main script: [javascript]
function sendRequest() {
FB.ui({
method: 'apprequests',
message: 'Test',
title: 'event invitation for up to 20 friends',
max_recipients: 20,
},
function (response) {
if (response && response.request_ids) {
var requests = response.request_ids.join(',');
var invite_ids = new Ajax.Request('/facebook/handle_invitation.php', {
onSuccess: function(test) { alert('Done!'); },
method: 'post',
parameters: {tid: '<?php echo $target_id; ?>',
request_ids: requests,
eid:'<?php echo $event_id; ?>',
token: '<?php echo $access_token; ?>'}
});
} else {
alert('canceled');
}
});
return false;
}
* and in 'handle_invitation.php' (called from request response):
if( isset($_POST['request_ids']) && isset($_POST['uid']) ) {
$target_id = $_POST['tid'];
$event_id = $_POST['eid'];
$access_token = $_POST['token'];
$requests = explode(',',$_POST['request_ids']);
foreach($requests as $request_id) {
$request_data = $fb->api("/$request_id?$access_token");
$invite_id[] = $request_data['to']['id'];
$fb->api("/$request_id?$access_token", "DELETE");
}
//invite friends to my event
$return = $fb->api(array(
'method' => 'events.invite',
'eid' => $event_id,
'uids' => $invite_id,
'personal_message' =>"Einladung zu meinem Event"
));
}
Hope this was not too detailed. I'd appreciate any help, since after days of reading and experimenting I'm finally stuck at this point. Thx!
The graph api now allows you to invite users by user_id. See http://developers.facebook.com/docs/reference/api/event/
invited
Create
You can invite users to an event by issuing an HTTP POST to /EVENT_ID/invited/USER_ID. You can invite multiple users by issuing an HTTP POST to /EVENT_ID/invited?users=USER_ID1,USER_ID2,USER_ID3. Both of these require the create_event permission and return true if the invite is successful.
I don't think "sent event invitation" is in the GRAPH API yet. It is available in REST API but its not working as we expect.
I found some known issues and limitations with facebook events. Please see the links below from the official documentation on facebook
Limitation on number of people that could be invited to an event.
http://www.facebook.com/help/?faq=12576#!/help/?faq=202545109787461
Event members are not receiving messages I have sent.
http://www.facebook.com/help/?page=786#!/help/?faq=188295427885002

using facebook stream publish

I want to publish a URL as an attachment to a friends wall:
var attachment={'name':'favor','href':'http://128.196.239.71/movie.php?mid=<?php echo $_GET['mid']; ?>'};
Facebook.streamPublish('',attachment,null,friends[i],comment,callback);
Doing the above gives me a Facebook undefined, what should I do to remedy this?
Do I need to set a special permission in order to do this to the sender of this message?
You do need the stream.publish permission in order to use the stream.publish method or the equivalent graph API call.
You can check that the user has already granted this permission with something like this:
FB.getLoginStatus(function(response) { if (response.perms) { /* check perms */ } })
You can request the permission with something like this:
FB.login(function(response) { /* check perms */ }, {scope: 'publish_stream'})
Then in the response you can check to see if it was actually granted, then you should be able to do stream publish calls.
However, I don't recognize the format of your call "Facebook.streamPublish". I think the new API requires you to do a call more like
FB.api({method: 'stream.publish', message: 'hello'}, function(response) {})
Alternatively to all this, you can use the dialogs API to create a post and show it to the user, and have them approve it or disapprove it. This does not require the stream.publish permission. Something like this (the example given in the FB.ui API docs):
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'http://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.',
message: 'Facebook Dialogs are easy!'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
At the rate Facebook changes, I hope some of this information is still accurate by the time you read it (or even accurate to begin with).

Facebook Javascript SDK: Tag another user in my wall post?

We are using the Facebook Javascript SDK to allow users to post content to their wall. In the message that gets posted, is it possible to tag another user, similar to how you can when typing a post on facebook.com? (using something like #person)
We are using:
FB.api('/me/feed', 'post', { message: 'This post came from a test. #someuser'}, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
The end result would then be a post that tagged the #someuser user.
The Facebook API doesn't currently support tagging of users like this. That functionality is limited to the actual site itself.