• This repository has been archived on 12/Jul/2023
  • Stars
    star
    253
  • Rank 159,908 (Top 4 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sample projects for the Facebook Instant Games platform

Instant Games Examples

This repository contains a collection of examples that show how to use the Facebook Instant Games SDK (FBInstant). There is also an excellent page here (https://www.facebook.com/fbgaminghome/developers/get-started) that can help you get started with the Facebook Instant Games.

Pre-requisites

  1. Install Node JS
  2. Install Yarn
  3. Download or clone this repository

Setup

  1. Make sure that your Instant Game app is setup. For more information see our Setup Guide
  2. In the root folder of this repo, run
    $ yarn install
  3. Copy or rename the file config.template.json to config.json and replace the information needed from your app.
    {
    	"FB_appId":"<YOUR_APP_ID_HERE>",
    	"FB_uploadAccessToken": "<YOUR_UPLOAD_TOKEN_HERE>",
    	...
    }

Your app ID can be found at the landing page of your app's dashboard.

Your upload access token can be found on the Instant Games -> Web Hosting tab of your app's dashboard.

Client-side examples:

Client-side examples are contained in the examples/ folder:

  • ads: Shows how to display Rewarded Videos and Interstitial Ads
  • bots: Shows how to send data from the game client to a bot and vice-versa
  • cross-promo: Shows how to prompt the player to switch to another one of your Instant Games
  • hello-world: An empty project with the boilerplate in place to get you up and running quickly
  • in-app-purchases: Shows how to use payments inside of your Instant Game
  • leaderboards: Shows how to use leaderboards (global and context-specific) in your Instant Game
  • secure-backend: Shows how to validate data in your backend to make sure they are authentically coming from your Instant Game, to prevent cheating
  • sending-messages: Shows how to show messages from your game to the current context (conversation)
  • shortcuts: Shows how to create a mobile home shortcut to the game

Running Client-Side examples:

In order to run these examples you will need to use one of these tasks:

  • run-mock: Runs on localhost against a mocked version of the SDK
  • mock: It is the same as run-mock. Runs on localhost against a mocked version of the SDK
  • run-dist: Runs on localhost against the production SDK
  • dist: It is the same as run-dist. Runs on localhost against the production SDK
  • upload: Package and upload your game in order to test on mobile

Below are some examples of how to execute these tasks:

$ yarn run-mock --project hello-world

Will run the hello-world project from localhost against a mocked version of the SDK (returns dummy data for every call). This way of running projects is especially useful for quickly iterating on local changes done to any of the projects.

$ yarn run-dist --project sending-messages

This will run the sending-messages project with HTTPS from localhost and embed it into our embedded player which allows you to connect to the latest version of the SDK. All data returned from the SDK will be authentic an updated. In order to use this option, you need to correctly set the FB_appId property on config.json. If the app shows stuck in 0% loading, make sure to visit https://localhost:8000 and follow the instructions on your browser trust the development certificates.

$ yarn upload --project ads

This will package and upload the ads example to Web Hosting. After that you can set the game to production mode in order to test it from the uploaded build - and not localhost. This option is especially useful since it allows you to test on mobile devices (More information here)

Server-side examples

Server-side examples are contained in the servers-examples/ folder:

  • nodejs-backend: It's a working backend for the secure-backend client demo, that shows how to perform server-side validations for client-signed calls from Instant Games.
  • nodejs-bot: It's a working backend for the bots client demo, that shows how to send and receive structured data from a game client.

Running server-side examples

Before running any of the server side examples, make sure to copy or rename the template.env into .env and provide the necessary information.

You can run any of the server-side examples above by running the following commands on terminal:

$ cd /server-examples/nodejs-backend
$ yarn install
 yarn install v1.7.0
 [1/4] Resolving packages...
 [2/4] Fetching packages...
 [3/4] Linking dependencies...
 [4/4] Building fresh packages...
 Done in 6.86s.
$ node index
 Node app is running on port 5000

From that moment on, your server-side code is running on http://localhost:5000. By changing the client-side code to point to that endpoint, you can test the full end-to-end flow locally.

Alternatively, you can host your backend code in a service such as Glitch or Heroku

Note: for the nodejs-bot server-side demo, you will need to host your backend in an external server.(More information here)

License

Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.

The examples provided by Facebook are for non-commercial testing and evaluation purposes only. Facebook reserves all rights not expressly granted.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

f8app

Source code of the official F8 app of 2017, powered by React Native and other Facebook open source projects.
JavaScript
13,989
star
2

messenger-platform-samples

Messenger Platform samples for sending and receiving messages. Walk through the Get Started with this code. https://developers.facebook.com/docs/messenger-platform/quickstart
JavaScript
1,714
star
3

360-video-player-for-android

Sample code for creating a 360 video player on Android. Creates an OpenGL ES scene that renders a sphere textured with video frames from MediaPlayer playback. Does not use the NDK. This is a simple example of the core elements of 360 video rendering and is not intended to be production quality code. The code may be unstable. This is won't be maintained.
Java
616
star
4

messenger-bot-samples

Messenger Bot Samples
JavaScript
552
star
5

Canvas-Streaming-Example

This project contains example code showing how to go live on Facebook using a <canvas> element as a source.
JavaScript
337
star
6

audience-network

Open source projects to demonstrate SDK and sample code usages and integration, and to collaborate and support peers in this community.
319
star
7

oculus-networked-physics-sample

This is a networked physics sample for Rift built in Unity.
C#
308
star
8

WhatsApp-Business-API-Postman-Collection

A Postman collection that contains the full set of sample WhatsApp Business API calls.
287
star
9

graph-api-webhooks-samples

These are sample clients for Facebook's Graph API Webhooks and Instagram's Real-time Photo Updates API.
CoffeeScript
230
star
10

fbctf-2019-challenges

The challenge source code and solutions for FBCTF 2019
Python
200
star
11

original-coast-clothing

Sample Messenger App - Original Coast Clothing
JavaScript
197
star
12

whatsapp-api-examples

Examples of how to use WhatsApp Cloud API on the WhatsApp Business Platform
JavaScript
190
star
13

workplace-platform-samples

Sample code to enable Workplace customers to make the most of the features of the Workplace Custom Integrations platform.
PowerShell
182
star
14

ghc-hotswap

Example code for how we swap compiled code within a running Haskell process.
Haskell
172
star
15

threads_api

This repository contains a sample app for developers who are interested in integrating with the Threads API.
JavaScript
162
star
16

kotlin_ast_tools

Utilities and examples used in Meta to simplify migration from Java to Kotlin and maintenance of Kotlin code.
Kotlin
145
star
17

fblogin-sample

Sample implementations for developers to take as reference when building into fb login products.https//developers.facebook.com/docs/facebook-login/messenger-integration
JavaScript
115
star
18

sculpting-and-simulations-sample

Sample code that supplements the Sculpting And Simulations talk.
C++
94
star
19

live-comments-teleprompter

Example code shows how to retrieve comments and reactions for a Facebook Live video.
JavaScript
88
star
20

bucksamples

Samples for the Buck build tool.
Objective-C
72
star
21

original-coast-clothing-ig

Sample Instagram App - Original Coast Clothing
JavaScript
50
star
22

glTF-Renderer

Sample glTF Renderer for Android
Java
50
star
23

marketing-api-samples

Solution samples using the Facebook marketing API.
JavaScript
49
star
24

VRDeepLinkSDK

VRDeepLinkSDK provides a quick way to integrate your app to display a 360 photo/video content from Facebook.
Java
37
star
25

OpenNetNorad

Sample system to manage Uping and Upong (UdpPinger) instances, used to measure / graph network latency and loss on Linux
Python
37
star
26

android-native-library-merging-demo

Buck demo showing how to safely merge native libraries in Android apps.
C
36
star
27

reels_publishing_apis

This repository contains sample apps for developers who are interested in integrating with Reels APIs.
JavaScript
36
star
28

sdstudio

sdstudio project for image generation and modification
Python
30
star
29

rusty-bunny

a tool that lets you write smart bookmarks
Rust
21
star
30

pytorch-quantization-workshop

Code for a workshop hosted at the MLOps World Summit '22
Jupyter Notebook
15
star
31

lead-ads-webhook-sample

Sample code to accelerate client's adoption of Lead Ads and Conversion Leads products, by integrating with our advertising platform. Developers can also take this as reference when building integrations, without having to start from scratch.
C#
13
star
32

ListViewToRecyclerView

Library to help products migrate from ListView to RecyclerView.
Java
11
star
33

insights_dashboard

Insights Dashboard is a sample app that integrates with Meta's Insights APIs
JavaScript
11
star
34

fbrell

An interactive environment to explore the Facebook JavaScript SDK.
Go
11
star
35

GetRecommendations

A complete, sample android application that uses the Audience Network SDK.
Java
10
star
36

OptiMate

Sample codes that allows to fetch different Reach and Frequency curves from the Facebook Marketing API.
Python
10
star
37

discord-help-bot

This is the code used in a tutorial called "Build a Discord bot with Rust and Serenity"
Rust
9
star
38

share_to_reels_android

Android sample app with Share to Reels
Java
9
star
39

share_to_reels_ios

iOS sample app with Share to Reels
Swift
7
star
40

f8-2014

For sample code used during sessions at the 2014 F8 conference.
Objective-C
7
star
41

cp_reference

We are building a 3rd party commerce platform partner reference implementation.
Python
7
star
42

typefast

An auto-deployable scripting environment that enables people to quickly leverage powerful automation tools.
JavaScript
6
star
43

python-typing-tutorial

A sample Python project to demonstrate basic type checking concepts and best practices.
Python
5
star
44

mit-dl-workshop

Jupyter Notebook
5
star
45

caldera-security-tests

This project was created to provide examples of a TTP Runner and Security Regression Pipeline using vulnerabilities discovered in MITRE CALDERA by Jayson Grace from Meta's Purple Team.
Go
5
star
46

transparent-automated-ads-demo-app

A demo web app to simulate the marketplace integration for Transparent Automated Ads
JavaScript
3
star
47

NeurIPS2018

Notebooks from the NIPS 2018 booth screen rolling deck
Jupyter Notebook
3
star
48

Facebook-Reels-Publishing-API-Postman-Collection

A Postman Collection that contains requests to upload Reels to Facebook
3
star
49

wamquery

Collection of runtime primitives for implementing a SQL-like query language
C
2
star
50

portal-sdk-samples

Sample implementations demonstrating how to integrate various Portal SDK feature modules into an Android App for Portal
Java
1
star
51

video-template-builder

An intuitive tool for creating dynamic video templates. Seamlessly integrate and customize videos, images, and audio files to produce new media at scale.
Python
1
star
52

cppcon24-async-demo

Demo application for C++con 2024 to showcase async stacks
Python
1
star