问题
I've managed to implement the "send Request" functionality for my App on facebook following the docs here
Now, in case user 'A' accepts a request sent to him by user 'B', I want user 'B' to get an app-specific gift (image). My question is, how would I find out it was user 'B' who invited user 'A'? (and not user 'C')
Thanks.
回答1:
Store the request id in your database along with the user B who initiated the request.
When user A clicks on the request they will be redirected to your app and Facebook will send you the request id. Look up the request ID in your db to get the user who initiated.
Some examples of getting the request id are included in the Facebook documentation about deleting requests.
Although not technical, you might also want to review the documentation on requests best practices which has a section on gifting.
An alternative is to get the sender from the graph api (note this is almost always slower than the above solution). By concatenating the user_id to the request_id you have a specific request object id, and you could issue a GET
request to the graph API that looks like this:
https://graph.facebook.com/<REQUEST_OBJECT_ID>?access_token=APP_ACCESS_TOKEN
In the response, the sender is in the from
attribute:
{
"id": "259855964134806_4",
"application": {
"name": "Betcafe",
"namespace": "betcafe-play",
"id": "240039049434634"
},
"to": {
"name": "Zuck",
"id": "4"
},
"from": {
"name": "Todd Chaffee",
"id": "532338216"
},
"message": "Join my team so we can pass balls to each other and help Milan win the weekly cup!",
"created_time": "2012-09-10T16:43:45+0000"
}
来源:https://stackoverflow.com/questions/12652986/send-facebook-request-and-get-a-gift-fb-api