Order Facebook highscores by country - javascript

I'm working on a Facebook game where scores get saved using the Scores API, while this all works fine, our client wants to be able to filter the highscores by country, I'm wondering if there's an easy way to do this.
When returning the scores, the user object only contains the ID and the name, it would be pretty stupid to get the country fo each user.

Easier way would be to get user country on application install time.
You can do this by adding user location permission to authentication dialog which appears first time
when the user visits your app.
See user_hometown and user_location here.
https://developers.facebook.com/docs/reference/api/user/
Then you can easily look all the user countries from your database, and sort according to country.

Related

Use Firebase and API keys to authenticate paid Shopify website themes

I'm trying to use Firebase as an authorization method for a paid Shopify website theme. The idea is the store owner purchases and downloads the theme files, and after purchasing also creates a firebase account with an email and password. Then an API key for the theme will be emailed to them. Once they have the API key they will input their account email and API key into the settings within the theme files. To authenticate the user the theme files will have some javascript that checks if the username and password inputted correspond to a existing user in the firebase database. If the email and API key inputted does not match to any user in the database then the user will be redirected to an error message HTML file, or get an error message popup that they cannot close saying to input the correct key.
Another possibility is to use the firebase firestore unique user ID instead of generating user API keys. Maybe this way there would be no need for using the firestore database.
Either way, this logic seems ok if it was a single user. But since it is a website theme file it is possible that every users website will get thousands of customer visits per day. Thus every customer that visits the clients site will trigger an authentication check with firebase with the clients email and API. So every user account on Firebase could potentially have thousands or maybe even hundred of thousands of logins and database queries everyday (depending on how popular their website is). So this is the part Im worried about.
Anyone have similar experience using Firebase for website theme authentication? Perhaps I am going about it all wrong here. Or maybe Firebase is just the wrong tool for this job.
Appreciate any input!

How to have one to one chat using firebase in AngularJS

I am trying to have a one to one chat feature using firebase. Right now, my structure of messages makes sense in the fb database but I am not able to implement one to one chat feature using firebase's api in angular. I am able to spam a chat room where all the users can see everyone's messages but i would like to have a one to one chat feature in my application. My structure is good in the firebase database and i just need to manipulate my javascript code to make it work. My code is as follows.
function chatController($scope,$firebaseArray) {
var ref1=firebase.database().ref().child('users/59c1c11cec/chats/-KuRshPYbO_d9B');
$scope.chats=$firebaseArray(ref1);
var ref=firebase.database().ref().child('chats/-KuRshPYbO_d9B/messages');
$scope.messages=$firebaseArray(ref);
$scope.send=function(){
$scope.messages.$add({
message:$scope.messageText,
// date:Date.now()
})
}
}
I am able to create a one to one chat between two users by hard coding their user ids, but I was wondering if firebase's api is able to do this dynamically. If yes, how would I do it? For reference, 59c1c11cec is the current logged in user id, -KuRshPYbO_d9B is the other person's id who the current person is starting a conversation with which I don't have any access to in my own database but only in firebase's database. And using that users id I retrieve the messages between the two users. How will I be able to achieve this? I just need to replace the hard coded values with the values I talked about.Thanks a lot in advance!

Firebase one to one chat implementation for web

I implemented friendly chat. But that is group chat. I am new to firebase. Need docs for creating one to one web chat. How to get list of user accounts and selecting single user to send message? Please help me
If the users communicating have user IDs uid_1 and uid_2.
The database structure should be:
contacts
--uid1
--uid2
--uid3
-- so on (1)
--uid2
--uid1
--uid4
-- so on (2)
messages
--uid1
--uid2
-- Push messages here.(3)
--uid2
--uid3
-- Push messages here also.(4)
Adding Contacts
If USER 1 knows USER 2 you can add USER 2 in location (1) and add USER 1 in location (2). Since you are implementing with user IDs the USERS will be able to send messages if they know the other USER's uid. You can send Chat Invites to exchange uids.
Adding Messages
If USER 1 or USER 2 sends a message add at locations (3) and (4). This implementation will make sure that even if USER 1 deletes a conversation with USER 2, USER 2 will still have a copy and thus ensuring privacy.
These are the key elements to make a basic one-on-one Firebase Chat App.
NOTE: User IDs are provided by Firebase on successful authentication.
Maybe try breaking your problem into individual milestones and learn how Firebase works as you need help in each milestone.
According to what you have written, you have to:
Authenticate Users (https://firebase.google.com/docs/auth/)
Save those user profiles onto the Real-Time Firebase Database in the following data structure (https://firebase.google.com/docs/database/)
List those users in a List / RecycleView (learnhowtoprogram.com/android/data-persistence/firebase-recycleradapter)
Manage the conversation through listeners in the adapter that reference child nodes which serve as rooms between 2 people.
Think about how to make your structure as efficient as possible such as not saving conversations twice under each user but rather saving a reference to a separate 'conversations' node.
I recently implemented this in my location-based app (Occupapp) if you want a live example. You will have to register, add a service and log in from another device and select that service to chat to the owner.

Facebook Graph API 2.2 mutual friends

So I've been trying for this for a couple of days, trying to figure out how to use Facebook's Graph API v2.2 to get mutual friends between two users. I understand that I can only get the mutual friends between two users that are using the FB App and that's cool.
The app has the following approved items:
email
public_profile
user_birthday
user_friends
user_hometown
user_location
user_relationships
user_website
My scenario is this:
A user (user A) register to the FB App
Another user (user B) registers
User A looks at the user B's profile
The profile should display the mutual friends between the two users
I've tried to play around in the Graph API Explorer
/v2.2/app_scoped_user_id?fields=context.fields%28mutual_friends%29
and
/v2.2/user_id?fields=context.fields%28mutual_friends%29. These just returns an ID field with the ID I provided and nothing else.
I'm all out ideas, and the docs isn't helping much either. Can someone explain how to do it?
I will be using it in an Angular app but as long as I can get the URL to fetch the correct thing I can translate it into Javascript.
For v2.3 - https://developers.facebook.com/docs/graph-api/reference/v2.3/user.context/mutual_friends
Between friends make sure the user_id in the query is the Facebook id of the other friend not the current user whose access token you are using.
GET /v2.3/{other_user.user-id}?fields=context.fields%28mutual_friends%29
For querying mutual friends between two non-friends you need to add a server appsecret_proof parameter plus the user access token.

Displaying friends' user who authenticated the app

I'm going more in depth in the Facebook javascript sdk but I am still new to it. I would like to display for every user on my website who logged with Facebook, their friends' pictures who also authorized the app. It is clearly and simply possible by using PHP SDK, but I only want to make use of javascript SDK to improve the speed of my site. Does anyone have an idea ?
Best,
Newben
You can use FQL to query the current user's friends SELECT id, name FROM user where uid IN (SELECT uid1 FROM friends WHERE uid2=me()) AND is_app_user=1. This query does two things. Finds all the friends and find only the friends who have your app installed.
For additional information see:
http://developers.facebook.com/docs/reference/fql/user/
and
http://developers.facebook.com/docs/reference/fql/friend/

Categories