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.
Related
I have a backend running GraphQL, MongoDB + Mongoose, and Apollo. This application has functionality for user accounts and a friends list. Each user can login to their account and see a list of friends with their current 'status'; If a friend changes their status, I need that change to be reflected on the user's side. An example of this is like facebook's "green dot" on messenger that tells you when one of your friends is online using the application.
I have been searching documentation for GraphQL and have been suggested either Subscriptions or Live Queries. Subscriptions seem to be the majority of suggestions from what I understand, live queries are not officially part of GraphQL or were dropped.
Does anyone have a solution to getting "live" data with GraphQL/MongoDB that doesn't involve polling for this scenario?
You already seem to have your answer: subscriptions!
Using your example, consider two users - mikep17 and mcy. You are mikep17, logged into your application and viewing your list of friends and their statuses. I am your friend, and I log in as you are viewing this list, and you want to see that in your application's UI.
On the frontend, in your application's instance, your application will execute a subscription to some event. Let's call it friendStatusChange. Now your application is "listening" for that event in order to respond accordingly. Let's assume that when your application receives the event, it can parse out the information that "I" (mcy) have changed from offline => online and then use that to add the "green dot" next to my username.
On the backend, your GraphQL server will have code that handles your user functionality - logging in, logging out, etc. It will need to be enhanced to hook into these actions and "publish" the friendStatusChange event as applicable.
Now, instead of your client constantly asking (polling) "did a friend's status change? how about now? now?", it can just listen and wait for your server to tap it on the shoulder and say "hey buddy, your friend mcy's status changed".
I plan to generate Facebook events (Conversion API) on server side when the user completes registration process. These events will be used for advertising my solution in Facebook and tuning target audience on registration events.
I use POST request to https://graph.facebook.com/v9.0/289777498957502/events to send events. I have to pass user_data entity inside a body of this request. This user data can be email address, click id, user IP address or something else.
I don't have any of these on server side but I can get it.
The problem is that I don't understand why Facebook needs user data and what exactly it needs as data. I can send everything to Facebook but I need to understand mandatory information it requires.
Do you know what should be sent as user data?
As an option I can send internal ID in my system of each user inside user data but I'm not sure Facebook will be happy with that.
Facebook manuals are a pure joke. Literally all are outdated and no information on user data content and why it's required.
The problem is that I don't understand why Facebook needs user data
Because your conversion is (ideally) supposed to get connected to an actual user account. Facebook knows, who the user is, as long as we are on the client side, and their pixel is embedded somewhere - they can make the cross-domain requests in the background, to see who is currently logged-in to Facebook on the device. But if you send conversion data later, from your server - how would they be supposed to associate that with a specific user then, if you don’t send them any data that could identify one?
and what exactly it needs as data.
If you have anything that can uniquely identify the Facebook user, then send that.
Otherwise, send as much data as you can – to increase the posibility, that Facebook will be able to match this to a specific individual.
Check the list they provide under https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters
If the user is logged in to your Facebook app while they are on your site, then send the fb_login_id – that is as unique and specific, as can be.
If you don’t use Facebook login on your site, or the user can also perform the action in question without being logged into your Facebook app - then send whatever you have, that identifies them on your end.
In case no unique match is possible, then send as much as possible - first & last name, phone number, date of birth - all those help to narrow down who the user might be on Facebook’s side.
The same data, or at least as much of it as is available at this time, should also be send with the pixel tracking code on the client side already. https://developers.facebook.com/docs/facebook-pixel/advanced/advanced-matching/ has details on that.
My goal is to make a website, in which user could customize a photo and then provide his friends indicators like name or id. My next task is to fetch that info from database and send messages on specific date to provided users. Ex birthday wishes, greetings, and so on.
I studied facebook send api for a few days now and couldn't find solution for myself. If I want to send message, I need to have Page-scoped id of user, which is acquired when the person text you first, which is not desired, because person wouldn't know what it is.
Also I was looking into Customer matching API, also seems to require the same PSID. The next thing I checked was Send Dialog API, which seems to send messages instantly, but not on the specific date. Also I checked unofficial facebook-chat-api, which asks for user ID, whereas I can find my id, I couldn't find ids of my friends.
So I just want to know is it even possible, if yes, I'd really appreciate your help.
User to User communication is not possible (and not allowed) in an automatic way, there is no API for it except for the Send Dialog. The Messenger platform is for page to user communication only.
Do not use inofficial tools, they are not allowed and might get you banned.
While coding I have started wondering if there is a possibility to perform an action before the actual request is send.
For example I have a code:
FB.ui({method: 'apprequests',
title: 'The Challenge Game!',
message: 'I challenge you!',
}, challengeCallback);
And I would like my user to be able to challenge a friend only once - that means, If a challenge exists in DB connecting two users, there should not be another challenge created until the first one is finished or expired.
So between picking friends and sending requests there should be a function call.
However I know, that I won't get users fb_id before the request is actually send.
I can always prompt my user, after choosing friends, that the challenge for that particular person already exists and is pending. But what happens to request that is waiting for the challenged in his/hers inbox?
Is there something I can do not being made to create my own friend picker? Maybe alter FB.ui somehow?
When you look at the description of the Requests dialog, you’ll notice the parameter exclude_ids, by which you can specify user ids that will be excluded from the multi-friend selector.
So if you look up in your database which of their friends your user has already send a request to, you can put those ids in there.
Only cave-at: This parameter is not supported on mobile devices; so if you are targeting those, you might have to look for another solution (which would be most likely to create your own multi-friend selector) – but I’m not sure right now whether this restriction only applies to native mobile apps; maybe when using the JS SDK in a web-app it’ll work on those as well (the wording in the docs is not totally clear on that).
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.