{"id":4310,"date":"2019-04-07T11:59:10","date_gmt":"2019-04-07T11:59:10","guid":{"rendered":"http:\/\/www.drmop.com\/?page_id=4310"},"modified":"2021-03-11T09:27:49","modified_gmt":"2021-03-11T09:27:49","slug":"getting-the-players-information","status":"publish","type":"page","link":"http:\/\/www.drmop.com\/index.php\/facebook-instant-games-tutorials\/getting-the-players-information\/","title":{"rendered":"Getting the Players Information"},"content":{"rendered":"<p>Welcome to the <a href=\"\/index.php\/facebook-instant-games-tutorials\/\">Facebook Instant Games SDK Tutorials<\/a>. This series of tutorials covers many aspects of using the Facebook Instant Games SDK.<\/p>\n<p>In this tutorial we will look at the important process of getting the players details and other important information to enable you to personalise the players gaming experience.<br \/>\nThe Facebook Instants SDK provides you quite a bit of information about the device that the player is playing the game on as well as about the player themselves.<\/p>\n<h1>Device specific information<\/h1>\n<h2>Players locale<\/h2>\n<p>One of the most important pieces if information you can get is the players locale, you can get this by calling:<\/p>\n<p>[sourcecode language=&#8221;js&#8221;]<br \/>\nFBInstant.getLocale();<br \/>\n[\/sourcecode]<\/p>\n<p>This returns a string of the users language locale in the format \u201cen_US\u201d. You can use this to provide text and art work in different languages.<\/p>\n<h2>Players device platform<\/h2>\n<p>You can grab the players device platform by calling:<\/p>\n<p>[sourcecode language=&#8221;js&#8221;]<br \/>\nFBInstant.getPlatform();<br \/>\n[\/sourcecode]<\/p>\n<p>This returns a string containing either WEB, IOS or ANDROID.<\/p>\n<h1>Player Specific Information<\/h1>\n<h2>Player ID<\/h2>\n<p>Each player that plays your game has an ID associated with them, note that this ID is scoped to your game and is not consistent across different games. This is to prevent you tracking the same users across multiple games. You can collect this ID by calling:<\/p>\n<p>[sourcecode language=&#8221;js&#8221;]<br \/>\nFBInstant.player.getID();<br \/>\n[\/sourcecode]<\/p>\n<p>A string representing the players ID will be returned. You can use this ID in your back-end to identify users of your game and assign data to them. This ID is also useful for users that sign up to receive notifications from your bot as well as filtering out the player from a list of all users.<\/p>\n<h2>Player Name<\/h2>\n<p>Using the players name when addressing them in the game or in context messages \/ bot notifications adds a level of personalisation that can help players connect with your game. You can collect the players name by calling:<\/p>\n<p>[sourcecode language=&#8221;js&#8221;]<br \/>\nFBInstant.player.getName();<br \/>\n[\/sourcecode]<\/p>\n<h2>Players Photo<\/h2>\n<p>Using the players profile photo is a great way to add personalisation into the game. To retreve the players photo URL you call:<\/p>\n<p>[sourcecode language=&#8221;js&#8221;]<br \/>\nFBInstant.player.getPhoto();<br \/>\n[\/sourcecode]<\/p>\n<p>However this only retrieves the players photo url and not the photo itself. To retrieve the actual photo you will need to download it:<\/p>\n<p>[sourcecode language=&#8221;js&#8221;]<br \/>\nvar image = new Image();<br \/>\nimage.crossOrigin = &quot;anonymous&quot;; \/\/ Allow cross origin access<br \/>\nimage.onload = function()<br \/>\n{<br \/>\n    \/\/ Image loaded<br \/>\n}<br \/>\nimage.onerror = function()<br \/>\n{<br \/>\n    \/\/ Image did not load<br \/>\n}<br \/>\nimage.src = FBInstant.player.getPhoto();<br \/>\n[\/sourcecode]<\/p>\n<p>Once loaded you now have a HTML5 Image object that you can render to wherever you like. I tend to use the players profile pic to show the players avatar in leaderboards, in messages and in-game.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to the Facebook Instant Games SDK Tutorials. This series of tutorials covers many aspects of using the Facebook Instant Games SDK. In this tutorial we will look at the important process of getting the players details and other important information to enable you to personalise the players gaming experience. The Facebook Instants SDK provides [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":4280,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-4310","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/pages\/4310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/comments?post=4310"}],"version-history":[{"count":9,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/pages\/4310\/revisions"}],"predecessor-version":[{"id":4624,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/pages\/4310\/revisions\/4624"}],"up":[{"embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/pages\/4280"}],"wp:attachment":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/media?parent=4310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}