Platform

Add Back4App to your App project

Introduction

Now that you have created an App at Back4App the next step to fully use Back4App resources is to install Parse SDK and connect your App project to Back4App platform.

Parse SDK is available to many technologies, you just need to choose which most fits your project. After installing the SDK you will have to look for your App keys on Back4App platform and insert those keys in your project. So, once you compile/run your project, you will be already connected to Back4App.

By connecting to Back4App and using the Parse SDK, your development effort will be much lower. You will be able to easily perform complex queries, call your cloud functions, send push from the client side, access integrations made through Back4app, etc.

Goal

  • To connect your software project to Back4App platform.

Prerequisites

To complete this tutorial, you will need:

  • An app created at Back4App.
  • An application software project environment ready to use.
  • Find your application keys at Core Settings, go to Server Settings > Core Settings > Settings > App Id and other.

Step 1 - Install Parse SDK

Now, you can follow these instructions to install Parse SDK into your project. You just need to select the right guide to the technology of your project.

Parse SDK for JavaScript can be used in a large amount of platforms and frameworks. To deal with it, the Parse npm module contains many versions to use in different environments. Below, you can choose 4 possibilities to install the Parse JS SDK:


1. Install the NPM module

We strongly encourage you to use the latest Parse NPM module. To do so, run the following command.

$ npm install parse --save

2. Install the SDK

1
2
3
4
var Parse = require('parse/node');

Parse.initialize("APP_ID","JS_KEY"); //PASTE HERE YOUR Back4App APPLICATION ID AND YOUR JavaScript KEY
Parse.serverURL = 'https://parseapi.back4app.com/'

1. Install the NPM module

We strongly encourage you to use the latest Parse NPM module. To do so, run the following command.

$ npm install parse --save

2. Install the SDK

1
2
3
4
5
import { AsyncStorage } from 'react-native';
import Parse from 'parse/react-native';

//Before using the SDK...
Parse.setAsyncStorage(AsyncStorage);

1. Install the NPM module

We strongly encourage you to use the latest Parse NPM module. To do so, run the following command.

$ npm install parse --save

2. Install the SDK

1
2
3
4
5
6
7
8
9
10
11
12
13
import * as Parse from 'parse';

@Component({ ... })

export class AppComponent {
  ...

  constructor() {
    // Initialize your Parse App Keys
    Parse.initialize("APP_ID","JS_KEY"); //PASTE HERE YOUR Back4App APPLICATION ID AND YOUR JavaScript KEY
    Parse.serverURL = 'https://parseapi.back4app.com/'
  }
}

1. Load external file in HTML document

After creating your index.html, install Parse SDK direct on it, inside the <head> tag, using the code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html>
<head>
  <title>My First Application</title>
  <script type="text/javascript" src="https://npmcdn.com/parse/dist/parse.min.js"></script>
  <script type="text/javascript">
    Parse.initialize("APP_ID","JS_KEY"); //PASTE HERE YOUR Back4App APPLICATION ID AND YOUR JavaScript KEY
    Parse.serverURL = 'https://parseapi.back4app.com/'
  </script>
</head>
<body>
  <!--
    Your code
  -->
</body>
</html>


Facing any trouble? Feel free to check the complete Install Parse SDK guide to JavaScript projects.
Also, feel free to check the official Parse Documentation regarding Parse SDK for JavaScript.

Gradle set up

Go to your Android Studio Project and find the build.gradle (Module:app) file. After that, copy and paste the code snippet right after the dependencies{} tag.

1
2
3
4
5
6
7
8
9
// ... code
dependencies {...}

repositories {
  mavenCentral()
  jcenter()
  maven { url 'https://jitpack.io' }
}

It’s also necessary to look in the android{} tag if the compileSdkVersion of your app is 27 or higher and also if the targetSdkVersion of your app is 27 or higher. If they aren’t, you must change these versions to 27 or higher, otherwise your Parse SDK for Android may not work properly.

Install the Parse Android SDK

To install the latest Parse Android SDK in your application, continue in the build.gradle (Module:app) file and copy and paste the code snippet inside the dependencies{} tag.

1
2
3
4
5
6
7
android {...}

dependencies {
  // code...
  // Don't forget to change the line below with the latest version of Parse SDK for Android
  implementation "com.github.parse-community.Parse-SDK-Android:parse:latest.version.here"
}

You can find out which is the latest version of Parse SDK for Android at Jitpack Website.

Facing any trouble? Feel free to check the complete Install Parse SDK guide to Android projects.
Also, feel free to check the official Parse Documentation regarding Parse SDK for Android.

Install SDK Arduino

First off, download here the Parse SDK for Arduino. Then, open the Arduino IDE to add the .ZIP library. To do so, navigate to Sketch > Include Library > Add .ZIP Library and select the downloaded file. After that, you will be able to see the Library and to import it to your Project, by doing what is shown in the following image.

Facing any trouble? Feel free to check the official Parse Documentation regarding Parse SDK for Arduino.

Install CocoaPods and Import Parse

Xcode can use CocoaPods as dependency manager for Swift and Objective-C Cocoa projects. To install CocoaPods, copy the following code snippet and paste it into your terminal and hit return.

$ sudo gem install cocoapods

You can refer to CocoaPods Getting Started Guide for additional details.

Connect your Parse App

Open your project’s AppDelegate file to set up app’s credentials. Parse SDK for iOS uses these settings to connect to the Back4App servers. At the top of the file you should see a function called didFinishLaunchingWithOptions. Paste the following code snippet inside this function, and make sure it is above the line that says return true.

At the top of your AppDelegate.swift file make sure to include Parse as a module by using the following code snippet right below import UIKit.

AppDelegate.swift

1
    import Parse

At the top of your AppDelegate.m file make sure to include Parse as a module by using the following code snippet right below #import "AppDelegate.h".

AppDelegate.m

1
#import <Parse/Parse.h>


Facing any trouble? Feel free to check the complete Install Parse SDK guide to iOS Swift and iOS ObjC projects.
Also, feel free to check the official Parse Documentation regarding Parse SDK for iOS.

We need to add some libraries to set up Parse SDK for .NET. We will get them through Nuget Packages. To do so, go to Microsoft Visual Studio and at the Solution Explorer, click on your app’s name and go to Manage NuGet Packages....

Then, click on Browse to search and install the packages parse by Parse and Xamarin.Android.Support.v7.AppCompat by Xamarin Inc.

Facing any trouble? Feel free to check the official Parse Documentation regarding Parse SDK for .NET.

Find this project page at GitHub and clone it. Then, open it on Unity3D.

Facing any trouble? Feel free to check the official Parse Documentation regarding Parse SDK for Unity.

You can use different ways to install the Parse SDK for PHP. We will show a couple of them here. Note that the Parse PHP SDK requires PHP 5.4 or newer.

With composer

Create a composer.json file in your projects root folder, containing the following.

{
    "require": {
        "parse/php-sdk" : "1.4.*"
    }
}

Now, you need to run the “composer install” to download and set up the autoloader. After that, you can require it from your PHP script, using the code below.

1
require 'vendor/autoload.php';

With Git

Go to Parse SDK for PHP page on GitHub and clone it. You can do this by using your favorite GitHub client or via terminal, as shown below.

$ git clone https://github.com/parse-community/parse-php-sdk.git

After that, inside your PHP file, you need to include the autoload.php to automatically load the Parse SDK classes.

Facing any trouble? Feel free to check the official Parse Documentation regarding Parse SDK for PHP.

Step 2 - Insert your Keys and initialize Parse SDK

To completely connect your application to Back4App, you need to set up your app keys (After the Login, go to Server Settings > Core Settings > Settings and find your keys) and initialize Parse SDK. To do so, you just need to select the right guide to the technology of your project.

To initialize Parse SDK in your JavaScript project, add the code below in your index.html file, inside <script> tag.

1
2
Parse.initialize("APP_ID","JS_KEY"); //PASTE HERE YOUR Back4App APPLICATION ID AND YOUR JavaScript KEY
Parse.serverURL = 'https://parseapi.back4app.com/'

Facing any trouble? Feel free to check the complete Install Parse SDK guide to JavaScript projects.
Also, feel free to check the official Parse Documentation regarding Parse SDK for JavaScript.

Save your Keys in the strings.xml file

Inside the strings.xml file, insert the following lines, with your application keys, in order to connect your project to Back4App Database.

./app/src/main/res/values/strings.xml

1
2
3
4
5
6
<resources>
    <string name="back4app_server_url">https://parseapi.back4app.com/</string>
    <!-- Change the following strings as required -->
    <string name="back4app_app_id">APP_ID</string>
    <string name="back4app_client_key">CLIENT_KEY</string>
</resources>

Give Permissions and set up your App

You need to grant permission for your Android app to access the internet network. To do this, add the following code snippet to your AndroidManifest.xml file right after the application tag.

./app/src/main/AndroidManifest.xml

1
2
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

Also, inside the application tag, add the following:

./app/src/main/AndroidManifest.xml

1
2
3
4
5
6
7
8
9
<meta-data
  android:name="com.parse.SERVER_URL"
  android:value="@string/back4app_server_url" />
<meta-data
  android:name="com.parse.APPLICATION_ID"
  android:value="@string/back4app_app_id" />
<meta-data
  android:name="com.parse.CLIENT_KEY"
  android:value="@string/back4app_client_key" />

Initialize Parse SDK

Create a Java file called App that extends Application. In this file, use the following line of code to import Parse.

1
import com.parse.Parse;

Inside App.java onCreate method, right after super.onCreate() call the following code:

1
2
3
4
5
6
7
Parse.initialize(new Parse.Configuration.Builder(this)
             .applicationId(getString(R.string.back4app_app_id))
             // if defined
             .clientKey(getString(R.string.back4app_client_key))
             .server(getString(R.string.back4app_server_url))
             .build()
);

Don’t forget to define this file in the AndroidManifest.xml. To do so, go to the AndroidManifest.xml file and add the following line of code inside the application tag:

1
android:name=".App"

If the name of the java file that extends Application that you created on the previous step isn’t “App”, don’t forget that the code above should have the correct name of the file (android:name=".name_of_the_file").

Facing any trouble? Feel free to check the complete Install Parse SDK guide to Android projects.
Also, feel free to check the official Parse Documentation regarding Parse SDK for Android.

After inslalling the Parse SDK for Arduino, you’re able to initialize Parse using the following code on the setup(){} method.

1
2
3
4
5
6
#include <Parse.h>

void setup() {
  Parse.begin("${APPLICATION_ID}", "${CLIENT_KEY}"); //PASTE HERE YOUR Back4App APPLICATION ID AND YOUR CLIENT KEY
  Parse.setServerURL("https://parseapi.back4app.com/");
}

Facing any trouble? Feel free to check the official Parse Documentation regarding Parse SDK for Arduino.

Use the code below inside your project’s AppDelegate file, inside didFinishLaunchingWithOptions function, above the line that says return YES or return true, to initialize Parse SDK.

AppDelegate.swift

1
2
3
4
5
6
let configuration = ParseClientConfiguration {
  $0.applicationId = "PASTE_YOUR_APPLICATION_ID_HERE"
  $0.clientKey = "PASTE_YOUR_CLIENT_ID_HERE"
  $0.server = "https://parseapi.back4app.com"
}
Parse.initialize(with: configuration)

AppDelegate.m

1
2
3
4
5
[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) {
    configuration.applicationId = @"PASTE_YOUR_APPLICATION_ID_HERE";
    configuration.clientKey = @"PASTE_YOUR_CLIENT_ID_HERE";
    configuration.server = @"https://parseapi.back4app.com/";
}]];


Facing any trouble? Feel free to check the complete Install Parse SDK guide to iOS Swift and iOS ObjC projects.
Also, feel free to check the official Parse Documentation regarding Parse SDK for iOS.

After waiting for installations to finish, open your strings.xml file and use the following code with your application keys.

.../App1/Resources/values/strings.xml

1
2
3
4
5
6
<resources>
  <string name="back4app_server_url">https://parseapi.back4app.com/</string>
  <!-- Change the following strings as required -->
  <string name="back4app_app_id">APP_ID</string>
  <string name="back4app_dotnet_key">DOTNET_ID</string>
</resources>

Also, in your Main Activity, you need to initialize these keys, using the following code.

1
2
3
4
5
ParseClient.Initialize(new ParseClient.Configuration {
  ApplicationId = GetString(Resource.String.back4app_app_id),
  WindowsKey = GetString(Resource.String.back4app_dotnet_key),
  Server = GetString(Resource.String.back4app_server_url)
});

Facing any trouble? Feel free to check the official Parse Documentation regarding Parse SDK for .NET.

You need to add your applicationId and dotNetKey to your project. To do so, click on Back4appDemoSence, find a GameObject that calls Back4appIntialize and paste there your keys, as shown in the image below.

Facing any trouble? Feel free to check the official Parse Documentation regarding Parse SDK for Unity.

After installing the Parse SDK for PHP, you can initialize it using the code below.

1
2
ParseClient::initialize( $app_id, $rest_key, $master_key);
ParseClient::setServerURL('https://parseapi.back4app.io','/');

Facing any trouble? Feel free to check the official Parse Documentation regarding Parse SDK for PHP.

Step 3 - Test your connection

To ensure that the connection between your project and Back4App has been established correctly, let’s make a test in which we will save an object in an open class of your app Dashboard at Back4App Website.

To do so, you just need to select the code that corresponds to the technology of your project, use it in your project and run it. After that, go to you app Dashboard at Back4App Website and see if your object has been created.

1
2
3
4
5
6
7
8
9
10
11
12
const MyFirstClass = Parse.Object.extend("MyFirstClass");
const myFirstClass = new MyFirstClass();

myFirstClass.set("name", "I'm able to save objects!");
myFirstClass.save()
.then((object) => {
  // Success
  alert('New object created with objectId: ' + object.id);
}, (error) => {
  // Save fails
  alert('Failed to create new object, with error code: ' + error.message);
});
1
2
3
ParseObject myFirstClass = Parse.Object.extend("MyFirstClass");
myFirstClass.put("name", "I'm able to save objects!");
myFirstClass.saveInBackground();
1
2
3
4
5
6
7
8
9
10
11
ParseObjectCreate create;
create.setClassName("MyFirstClass");
create.add("name", "I'm able to save objects!");
ParseResponse response = create.send();
if (!response.getErrorCode()) {
  // The object has been saved
} else {
  // There was a problem, check response.
  getErrorCode();
}
response.close(); // Free the resource
1
2
3
4
5
6
7
8
9
10
var myFirstClass = PFObject(className:"MyFirstClass")
myFirstClass["name"] = "I'm able to save objects!"
myFirstClass.saveInBackground {
  (success: Bool, error: Error?) in
  if (success) {
    // The object has been saved.
  } else {
    // There was a problem, check error.description
  }
}
1
2
3
4
5
6
7
8
9
PFObject *myFirstClass = [PFObject objectWithClassName:@"MyFirstClass"];
myFirstClass[@"name"] = "I'm able to save objects!";
[myFirstClass saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
  if (succeeded) {
    // The object has been saved.
  } else {
    // There was a problem, check error.description
  }
}];


1
2
3
ParseObject myFirstClass = new ParseObject("MyFirstClass");
myFirstClass["name"] = "I'm able to save objects!";
await myFirstClass.SaveAsync();
1
2
3
ParseObject myFirstClass = new ParseObject("MyFirstClass");
myFirstClass["name"] = "I'm able to save objects!";
Task saveTask = myFirstClass.SaveAsync();
1
2
3
4
5
6
7
8
9
10
11
12
$myFirstClass = new ParseObject("MyFirstClass");

$myFirstClass->set("name", "I'm able to save objects!");

try {
  $myFirstClass->save();
  echo 'New object created with objectId: ' . $myFirstClass->getObjectId();
} catch (ParseException $ex) {  
  // Execute any logic that should take place if the save fails.
  // error is a ParseException object with an error code and message.
  echo 'Failed to create new object, with error message: ' . $ex->getMessage();
}

After running the code choosed above, you can back to your Dashboard and refresh the browser to see the changes :)

Conclusion

At this guide, you have learned how to install Parse SDK in your project to connect your app with Back4App. We also have described how you can find your app keys.