get all outstanding user to user requests with only sender user_id and access token? - facebook

I tried $facebook->api('/me/apprequests/'); and that was blank even with 2 outstanding requests sent to 2 different friends. Nothing shows on graph explorer either.
What I need is a way to get this information without knowing the request ID, because I need to add this information to my database after they send a user to user request, to prevent them from sending more than one request to a friend per day. I know other apps do this, but I guess they aren't using FB.ui and probably record that info while sending the request?

There is no way to get requests that user sent via apprequests connection of user object, only those user received.
You can read the apprequests sent to a user by your app by issuing an HTTP GET request to /USER_ID/apprequests with user access_token.
You should store information about requests sent by application on your end if you need that info.

Related

Facebook Graph API - message a user that has blocked a page

What (if any) will be the result of the following use-case:
I have a FB page and I'm sending (private) messages back and forth with another FB user.
The user blocks my page.
(1) What will happen if I send a message to the user ? I guess the API will return a message with a certain HTTP code ?
Here it states that
https://developers.facebook.com/docs/messenger-platform/error-codes
You might also receive this error if a customer has blocked your business from messaging him or her.
(2) What happens if I keep sending messages to the user which has my page blocked ? Will FB see this as some kind of violation, or just send back same response ?
The FB graph API is as usual very hard to navigate.
Looking at various FB API pages, still not clear what could happen.
https://developers.facebook.com/docs/graph-api/reference/page/blocked
https://developers.facebook.com/docs/messenger-platform/reference/send-api
https://developers.facebook.com/docs/messenger-platform/error-codes

"Ask for gift" Facebook request without server

I want to implement "ask for help" feature in my game (Facebook Unity SDK). If user A asks user B for help, and user B accepts, user A will get a gift.
My game is a single player experience right now so we have not created a server. Is there anyway to know if user B has accepted the request when User A logs in again next?
The solution here involves storing information in a database:
send Facebook request and get a gift FB API
Not really, you must delete your request on accepting, so request can only be in pending state.
You can remember ID when you send request to a player, and check what pending requests exist, and if you don't find your ID there, you know request was either accepted or rejected, but that probably doesn't help.
You will need to store request data somewhere. You can use service like parse.com, where you can just push data from client without having to do much work server-side. Parse is free until your game gets big and after that 200$ should not be too much.

How can my app facilitate a message to multiple friends?

I have a facebook app that needs to allow a user to send a message to multiple friends (potentially all their friends) at once. This isn't any kind of spam, and I don't need the app to send the message incognito (behind the scenes), I just need to open a dialog with specific friends pre-populated (that the user has selected within my app in a prior step) and then send them a custom message. Is this possible? I see the api for sending a message to a single friend, and I see the API for inviting users to my app (but that's limited to some very small number of invitations per day)... what I need is a dialog that lets me send messages to as many of the user's friends as they want, but for me to control *which friends are selected... I don't want to give them control to add/remove from the friends list.
Is this possible?
No, the Send Dialog allows prefilling only a single friend, but would otherwise be the best option here if you need a custom message displayed to the recipient. You could get the user to send to several friends in a loop by prefilling this - or fire the dialog without prefilling and let the user chose who to send to - your app won't receive a callback with the recipient IDs but you could put a referrer param in the URL sent?
Failing that, the Requests dialog / 'invites' are the only thing you can prefill with multiple recipients without the expectation that your app will be shut down for spam shortly thereafter - there's no limit per day on the number of requests sent, but you don't get to set the message shown to the recipient.
In case this is helpful to anyone else, I just found this... it's a relatively new API (still in beta) that allows for (just about) exactly what I was asking for. I've tested it and it appears to work...
https://developers.facebook.com/blog/post/2012/08/31/reach-users-1-1-with-the-notifications-api/

Is there a reliable way to record user initiated facebook apprequests?

It seems like the only way to do apprequests from user to user is via a dialogue. It also seem like I would need to do a ajax post with the invite ids to my server to record them happening. It's a bit unreliable.
Is there a way where I can get a list of the requests without needing to do a post?
You can only list pending requests by calling /me/apprequests on the user. Any other requests that were processed, you need to save them at the initial point of the request.

Real-time Update

I really hope this is not a naive question but does Facebook real time updates work on user's status updates? if so can someone point me in the right direction because I can't seem to confirm this anywhere.
You can't subscribe to these user connections yet: home, tagged, posts, photos, albums, videos, groups, notes, events, inbox, outbox, updates, accounts
http://developers.facebook.com/docs/reference/api/realtime/
It's called long-polling. Look up node.js and long-polling ajax concepts.
Essentially the client makes an initial ajax request and waits for a response with no timeout set. Server-side JS will trigger an event when the user updates his/her status and send the response to any JS clients awaiting said response. The information gets updated, and immediately the client sends another request and waits for the next event.
You can subscribe to the 'feed' connection of your app users, which then also triggers on status updates.
URL = 'https://graph.facebook.com/%s/subscriptions' % appid
data = {'object': 'user',
'fields': 'feed',
'callback_url': callback,
'verify_token': verify_token,
'access_token': access_token,
}
res = requests.post(URL, params=data)
print res.content
print res.ok
The access_token must be an application access token, not a user access token. The above request will subscribe you to updates of all of your users! The message sent by the Facebook server will only include the user ID of the user, though, and no details about what happened. You have to figure that out yourself.