Why some messages are not sent by Facebook chat API? - facebook-fql

We've been running the Facebook Chat API on our app for months, but since recently we started to get 1 out of 5 messages that don't seem to be sent anymore.
For sending we use this:
sender_chat_id = "-#{uid}#chat.facebook.com"
client = Jabber::Client.new(Jabber::JID.new(sender_chat_id))
client.connect
client.auth_sasl(Jabber::SASL::XFacebookPlatform.new(client,
app_id,
access_token,
app_secret]
), nil)
# Send messages
client.send(jabber_message)
# Close chat client
client.close
and it seems to work. then we check if the message is sent with:
Fql.execute({
"query1" => "SELECT body FROM message WHERE thread_id IN (SELECT thread_id, recipients FROM thread WHERE folder_id = 1 AND #{receiver_uid} IN recipients ORDER BY updated_time DESC) ORDER BY created_time DESC"
}, {
access_token: access_token
})
And unfortunately sometimes the message just won't appear in the outbox.
EDIT:
The problem seems to come from messages sent to people that don't have a thread with the sender containing previous messages.
In those cases, the message sent by the Facebook chat API is not delivered.
However when if the sender sends a message to the receiver (or vice versa) "manually", the thread is opened and all the messages sent before by the API appear...

Related

How can I approve an XMPP subscription request 'later' in Smack ("Add later" functionality)?

Let us suppose that Alice sends a subscription request to Bob using the next code.
public bool AddBuddy(string jid) {
var roster = conn.Roster;
// 2` param is nickname
roster.CreateEntry(jid, null, null);
roster.SetSubscriptionMode(Roster.SubscriptionMode.Manual);
Presence subscribe = new Presence(Presence.Type.Subscribe);
subscribe.To = jid;
conn.SendPacket(subscribe);
}
When Bob has logged, it receives a popup where tell you if you want to added or not in the next method.
public void ProcessPacket (Packet p0)
{
Presence presence = p0.JavaCast<Presence> ();
var a = presence;
}
But I need to implement a "Add Later" functionality. I have no idea how to save the messages in the server and also how to receive all of them
You can delay the subscription as long as you want, there is no need to save the subscriptions packets on the server. And in order to query the deferred subscriptions requests, simply query the roster for subscriptions not in mode both.
One remark regarding your code: Roster.createEntry(String, String, String[] will automatically send the presence packat. No need to send it again.
No need to save anything on the server as it maintains pending subscribe requests automatically, ie. whenever you login to the server at a later time, the subscribe request will be pushed to you again (if it wasn't dealt with before). Therefore, just save the subscribe request locally in your application in a list or something whenever you receive it from the server, and show that local request list to the user as a "Friend request page" for the user to accept/reject. If your application's lifecycle restarts, it will be receiving all pending subsribe presences again from the server (or whenever it re-logins). Let me know if this works for you.

How to get facebook pending friend requests through fql

I'm working on getting pending requests by fql. I've set up "read_requests" permission and used following fql:
SELECT uid_from,
message
FROM. friend_request
WHERE. uid_to = me()
But it doesn't work and I do not get anything.
Can anyone help me?
You need the read_requests permission for any friend requests that are sent by or to the current session user.
You can read a list of friend requests sent to the current user -
SELECT time,
message
FROM friend_request
WHERE uid_to = me()
Or, you can check the status of any friend request sent by the current user, but you have to provide the id of the user to whom the request was sent. You cannot retrieve all friend requests sent by the current user -
SELECT time,
message
FROM friend_request
WHERE uid_from = me()
AND uid_to = ID

deleting facebook requests

The facebook docs here say "it is the Developers' responsibility to delete a Request once it has been accepted". As far as I understand, when someone sends a request to multiple users on facebook like this:
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'test message'
}, requestCallback);
}
only one request_id is returned via requestCallback() function.
Then, if I delete the request when someone accepts it, how would other users accept the deleted request?
when user comes following the app request, you can get request id's using
$_GET['request_ids']
then retrieve all the request ids with which you can call graph api to delete the corresponding requests like below:
if(isset($_GET['request_ids']))
{
$request_ids = $_GET['request_ids'];
}
$request_ids = explode(",", $request_ids);
foreach($request_ids as $request_id)
{
$full_request_id = $request_id."_".$fbid; //$fbid is current user facebook id
$facebook->api("$full_request_id","DELETE");
}
Check out the Request ID Format section of the FB request overview page.
The actual graph path for a request actually sent to specific user is "request-id"_"recipient-user-id".
you can access to facebook on mobile mode (m.faceook.com)
1-access the invitation panel
2-display all the invitations
3-open console mode in chrome
4-activate jquery by cpying and pasting all the jquery.min code into console
and excecute this script :
$("._54k8._56bs._56bt").trigger("click");
that will cancel or the invitation sent

Requests 2.0, empty data in graph after successfully sending requests

I'm seeing some strange behaviour with Requests.
I initiate a requests dialog with:
method: 'apprequests'
to: 'someUid'
(and some data for message, title, data)
The user approves the Request, and I get back a valid response, giving me the request Id, the user Ids it was sent to, and the updatedFrictionless flag. However, when reading the request from the graph later with either:
https://graph.facebook.com/?ids=REQUESTID_USERID&access_token=RECEIVINGUSERTOKEN
or
https://graph.facebook.com/REQUESTID_USERID?access_token=RECEIVINGUSERTOKEN
I get back no data !
The first graph call will give me an empty array (an un-named array not 'data', just simply [ ] )
The second, gives me 'false'
REQUESTID is the request Id I get back from the original call, USERID is the receiving USERID.
The receiving user is me, and I do see the request in my notifications, but using the graph explorer to check my 'apprequests', its empty.
Any ideas? I have Requests 2.0 enabled, and call FB.init with frictionlessRequests: true..
Does it work with your app access token?

posting reply to inbox message?

I'm trying to post a reply to an inbox message by sending a POST request to /message_id/comments. Is this the correct way to send a reply to an inbox message ?
I'm getting the following error:
"error": {
"type": "OAuthException",
"message": "(#3) App must be on whitelist"
}
The token has every possible permission.
Do I have to ask that my app is added on a whitelist ? how to do so ?
I'm doing this in javascript+jQuery:
var params = {
access_token: token
, method: 'post'
, message: 'hi'
};
$.getJSON('https://graph.facebook.com/$message_id/comments?callback=?', params, function(json) {
});
Facebook apps by default aren't allowed to send messages on behalf of users. There is no permission you are missing. This is an extra level to prevent spam (beyond prompting the user who). You will have to contact Facebook to get your application whitelisted. I would try their developer group.
opened a support ticket right here:
http://developers.facebook.com/bugs/183144141763793?browse=search_4e8b140cbf26e6040457329
Tried all I can think of and googled for, still getting this issue
Like others have pointed out, there isn't a way to do this programmatically unless you are on Facebook's whitelist. However, I did find a way around this for my app. What I do is use Oauth to display messages from a user's FB inbox like normal. When the user clicks 'Reply' on a message, I just send them to the reply page on Facebook Mobile, like this:
$('.reply').click(function() {
var popup_window = window.open('http://touch.facebook.com/messages/compose?ids='+message_id, '_blank');
popup_window.focus();
});
Where message id is the Facebook id for the message they are replying to. In my case, I use PHP to echo the message id into a javascript variable or data-attribute when the page loads. Since the Facebook mobile page opens in a new tab, they don't even really leave my app. Since Facebook mobile has a very streamlined interface it isn't too distracting. It's not perfect, but it works and it's easier than trying to get whitelisted.